Monthly Archives: April 2015 - Page 7

How to use sysprocesses – ::fn_get_sql

DECLARE @Handle binary(20)
SELECT @Handle = sql_handle FROM sysprocesses WHERE spid = 52
SELECT * FROM ::fn_get_sql(@Handle)

SELECT * FROM sys.sysprocesses s CROSS APPLY fn_get_sql(sql_handle)

Quick Overview of DBCC CHECKDB

It includes all these 3 DBCC commands run individually

    DBCC CHECKALLOC
    DBCC CHECKTABLE
    DBCC CHECKCATALOG

If DBCC CHECKDB fails the best option is restore from the backup or try with repair allow data loss option by putting in emergency mode and then single user mode. If fixed move back to multi user mode again.

Autoclose, autoshrink, autoupdatestatistics

    autoclose – This setting closes the database asynchronously when it is not in use, freeing system resources.
    autoshrink – Enables automatic shrinking of database files during periodic checks.
    auto_update_statistics – Enables automatic updating of statistics for the database.
    auto_update_statistics_async – Enables asynchronous updates of statistics for the database.

How to check locks held by SQL Server


sp_getapplock
sp_releaseapplock

also check sp_MSacquireSlotLock & sp_MSreleaseSlotLock used in merge replication process

Access DAC in SQL Server

exec sp_configure ‘remote admin connections’, 1
reconfigure