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 ArticleMemory 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 ArticleClear 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 ArticleKill 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 ArticleSet database in emergency mode
ALTER DATABASE dbName SET Emergency –For SQL 2000 –update sysdatabases set status = 32768 where name = ‘dbName’
View ArticleSQL 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 ArticleFind 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 ArticleSQL 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 ArticleSimple 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 ArticleDelete 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 ArticleSuper 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 ArticleKill 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 Articlekick off sp from batch file
osql -U sa -P 3hn$ -S DC-CGWH2 -d master -Q “Exec sprebates ;” Filed under: T-sql
View Articlefix 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 ArticleNotes 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 ArticleSAN-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 ArticleIO 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 ArticleHow 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 ArticleFix 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 ArticleList 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
More Pages to Explore .....