DBCC Commands
DBCC Checkdb(‘dbname’|dbid) with estimateonly| - Physical_only|all_errormsgs|no_infomsgs
DBCC SQLPERF ( LOGSPACE ) it shows the space information of all database’s log file (log size and log space used in percentage)
DBCC CHECKALLOC (‘dbname’|dbid’) checks the consistency of disk space allocation structure for specified database. This DBCC cannot be run on tempdb.
DBCC CHECKCATALOG (‘dbname’|dbid’) checks the catalog consistency of database.
DBCC CHECKCONSTRAINTS (tabName|tabID|constraintName|constrantID) check the consistency of constraint.
DBCC CHECKFILEGROUP (FGname|FGid) checks the allocation and structural integrity of specified file group.
DBCC ShowFileStats – show the name of .mdf, location ot it, total extents and used extents
DBCC CHECKTABLE (tabName|tabID) checks the integrity of all pages of table
DBCC CLEANTABLE (dbname | dbid, tabname | tabID) reclaims space for dropped columns in table by using ALTER TABLE DROP COLUMN statement.
DBCC DBREINDEX (tabNam, index_name, fillfactor) - rebuilds index.
DBCC INDEXDEFRAG (dbname | dbID, tabName| tabID, indexName | indexID)
defragments index on specified table or view.
DBCC DROPCLEANBUFFERS removes all clean buffers from the buffer pool.
DBCC FREEPROCCACHE removes all elements of plan cache.
DBCC FREESYSTEMCACHE removes all unused cache entries from all cache.
DBCC OPENTRAN (dbName | dbID) display information about active transactions.
DBCC SHOW_STATISTICS (tabName, indexName) displays the stats information about specified index like last date of updated statistics.
update statistics tablexname or it updates the statistics update single statistics (update statistics tablename statisticsname)
DBCC SHOWCONTIG (tabNam | tabID | indexNam | indexID) displays the information about fragmentation about specified object.
DBCC SHRINKDATABASE (dbname|dbid, targent_per, notruncate|truncateonly) shrink the db.
DBCC SHRINKFILE (filename|fileid, target size, notruncate|truncateonly) shrink the specified file.
DBCC SQLPERF (logspace) Provides transaction log space usage statistics for all databases.
DBCC TRACEON(1222,-1) Deadlock trace. -1 means for all sessions.
DBCC traceon(1204) also gives the information about deadlock and locks on which table
DBCC TRACEOFF(1222,-1) Deadlock trace off for all sessions.
DBCC TRACESTATUS (traceNumber) displays the status of Trace.
DBCC UPDATEUSAGE (dbaname|dbid|tabname|tabid|indexname|indexid) corrects the pages and row count inaccuracies in the catalog views.
DBCC USEROPTIONS displays the SET options for the current user.
dbcc help('?') list all dbcc commands.
DBCC ERRORLOG OR sp_cycle_errorlog : if error log file in becoming very large, we can run this dbcc command to create new error log file without restarting the server.
DBCC TRACESTATUS – this will show the all enabled trace
DBCC INPUTBUFFER ( session_id [ , request_id ]) [WITH NO_INFOMSGS ]
Displays the last statement sent from a client to an instance of Microsoft SQL Server.
DBCC PINTABLE (database_id , table_id ) - Marks a table to be pinned, which means Microsoft® SQL Server™ does not flush the pages for the table from memory.
Comments