Quantcast
Channel: SQL DBA Scripts and Knowledgebase
Browsing all 38 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

Memory related scripts

–Internal memory distribution dbcc memorystatus – To find out how much memory has been allocated through AWE mechanism SELECT Sum(awe_allocated_kb)/1024 as ‘AWE allocated, MB’ FROM...

View Article



Image may be NSFW.
Clik here to view.

Memory 2005

Quick Intro •      VAS – Virtual Address Space •      Physical Memory & Swap File •      AWE mechanism & Locked Pages in memory on 64 bit •      Memory Pressure –   Internal (Virtual &...

View Article

Image may be NSFW.
Clik here to view.

Clear Logs Shrink Database

sp_helpdb dbName go alter database dbName set recovery SIMPLE go checkpoint go backup log dbName with no_log go dbcc shrinkdatabase(dbName) go – or  –dbcc shrinkfile (1,10)  –dbcc shrinkfile(2,10)...

View Article

Image may be NSFW.
Clik here to view.

Kill all users and set single user mode

USE master; GO ALTER DATABASE dbName SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO ALTER DATABASE dbName SET MULTI_USER; GO

View Article

Image may be NSFW.
Clik here to view.

Set database in emergency mode

ALTER DATABASE dbName SET Emergency –For SQL 2000 –update sysdatabases set status = 32768 where name = ‘dbName’

View Article


Image may be NSFW.
Clik here to view.

SQL profiler blocked processes report

sp_configure ‘show advanced options’, 1 ; GO RECONFIGURE ; GO sp_configure ‘blocked process threshold’, 15 ;  — processes exceeding 15 GO RECONFIGURE ; GO – view in profiler blocked process report...

View Article

Image may be NSFW.
Clik here to view.

Find tables/views not having index

SELECT SCHEMA_NAME(schema_id) AS schema_name,type_desc ,name AS name FROM sys.objects WHERE type in (‘U’,'V’) and OBJECTPROPERTY(object_id,’IsIndexed’) = 0 ORDER BY schema_name, name; GO

View Article

Image may be NSFW.
Clik here to view.

SQL Server Stress Utility

How to use the SQLIOSim utility to simulate SQL Server activity on a disk subsystem: http://support.microsoft.com/kb/q231619/

View Article


Image may be NSFW.
Clik here to view.

Simple batch delete

WHILE 1=1 BEGIN set rowcount 500000 delete from tblDocumentCust WAITFOR DELAY ’00:00:1′ end - -or while (select count(*) from table)> 0 Begin delete top(500) from table end

View Article


Image may be NSFW.
Clik here to view.

Delete Files

–Cannot use the ForFiles command as in the local delete, as it does not work on UNC locations DECLARE @FilePath VARCHAR(150) DECLARE @CmdString VARCHAR(200) DECLARE @FileMask VARCHAR(10) DECLARE...

View Article

Image may be NSFW.
Clik here to view.

Super Large updates

 –first develop filtered index, cursor and then go step by step USE [SapphireDataMart] GO CREATE NONCLUSTERED INDEX [addx] ON [Mart].[FACT_HOURLY_SALES] ([date_sid],[sale_type_sid]) INCLUDE...

View Article

Image may be NSFW.
Clik here to view.

Kill all users

CREATE PROCEDURE dbo.clearDBUsers     @dbName SYSNAME AS BEGIN     SET NOCOUNT ON       DECLARE @spid INT,         @cnt INT,         @sql VARCHAR(255)       SELECT @spid = MIN(spid), @cnt = COUNT(*)...

View Article

Image may be NSFW.
Clik here to view.

kick off sp from batch file

osql -U sa -P 3hn$ -S DC-CGWH2 -d master -Q “Exec sprebates ;” Filed under: T-sql

View Article


Image may be NSFW.
Clik here to view.

fix orphan users 2008

DECLARE @user SYSNAME DECLARE @SQL NVARCHAR(300) DECLARE cur_Users CURSOR FOR SELECT name    FROM sysusers    WHERE islogin = 1       AND isntname = 0       AND NAME NOT IN (‘guest’, ‘dbo’, ‘sys’,...

View Article

Image may be NSFW.
Clik here to view.

Notes on Execution Plans

Query submission – Relational engine then storage engine Relational Engine – Execution plans are created after query parsing and optimization. DDL not optimized. DML only. Algebrizer process to Query...

View Article


Image may be NSFW.
Clik here to view.

SAN-Intro

SAN basically removes or uncouples storage (disks and drives) from servers and attaches that storage directly to the network. scalable and flexible in their storage resource allocation. better and more...

View Article

Image may be NSFW.
Clik here to view.

IO Characteristics

How do I determine if I am hitting log bottlenecks? First look for associated wait types (dm_os_wait_stats): WRITELOG & LOGBUFFER Sample dm_io_pending_io_requests select vfs.database_id, df.name,...

View Article


Image may be NSFW.
Clik here to view.

How many files should a database have?

More io If a filegroup in SQL Server contains more than one file, SQL Server will “stripe” allocations across the files by using a proportional fill algorithm. If the files in the group have the same...

View Article

Image may be NSFW.
Clik here to view.

Fix Orphan Users – All versions

USE [master] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[sp_fix_user_logins]  @DBName VARCHAR(100)=’*',  @Action VARCHAR(20)=’Report’,  @User VARCHAR(100)=’*',...

View Article

Image may be NSFW.
Clik here to view.

List Unused tables and Indexes

SELECT OBJECT_NAME(i.[object_id]) AS [Table name] ,  CASE WHEN i.name IS NULL THEN ‘<Unused table>’ ELSE i.name END AS [Index name]  FROM sys.indexes AS i INNER JOIN sys.objects AS o ON...

View Article
Browsing all 38 articles
Browse latest View live




Latest Images