Database Console Commands (Transact-SQL)

From Wikipedia, the free encyclopedia
Jump to: navigation, search

The Database Console Commands (DBCC) are a series of statements in Transact-SQL programming language to check the physical and logical consistency of a Microsoft SQL Server database.[1] These commands are also used to fix existing issues.[1] They are also used for administration and file management.[2]

DBCC was previously expanded as Database Consistency Checker.[3]

Categories of DBCC Commands[edit]

Based on their uses, DBCC commands are made of three categories of statements. They are:

Category Uses Commands
Maintenance statements Maintenance tasks DBCC DBREINDEX, DBCC DBREPAIR, DBCC INDEXDEFRAG, DBCC SHRINKDATABASE, DBCC SHRINKFILE, DBCC UPDATEUSAGE, DBCC CLEANTABLE, DBCC DROPCLEANBUFFERS, DBCC FREEPROCCACHE
Status statements Status checks DBCC INPUTBUFFER, DBCC OPENTRAN, DBCC OUTPUTBUFFER, DBCC PROCCACHE, DBCC SHOWCONTIG, DBCC SHOW_STATISTICS, DBCC SQLPERF, DBCC TRACESTATUS, DBCC USEROPTIONS
Validation statements Validation operations on a database and database components such as table, index, file catalog, etc.[1] DBCC CHECKALLOC, DBCC CHECKCATALOG, DBCC CHECKCONSTRAINTS, DBCC CHECKDB, DBCC CHECKFILEGROUP, DBCC CHECKIDENT, DBCC CHECKTABLE,

DBCC NEWALLOC

Miscellaneous statements Miscellaneous tasks DBCC dllname (FREE), DBCC HELP, DBCC PINTABLE, DBCC ROWLOCK, DBCC TRACEOFF, DBCC TRACEON, DBCC UNPINTABLE
Source: MSDN Transact-SQL Reference (SQL Server 2000)

Operation of DBCC statements[edit]

DBCC DBREINDEX[edit]

This statement is used to recreate the indexes for a particular table.[4] This statement rebuilds indexes in a single step.[5] It also assigns fresh pages to reduce internal and external fragmentation.[5]

DBCC DBREPAIR[edit]

This statement is used to drop or delete a damaged database.[6] However, this command is no longer available with Microsoft SQL Server 2005 and later versions of Microsoft SQL Server.[7] Instead, it has been replaced by the DROP DATABASE Transact-SQL statement.[7]

DBCC INDEXDEFRAG[edit]

This statement is used to defragment the clustered and secondary indexes associated with the particular table.[8] The index defragmentation is carried out using the fill factor specified at the time of creation of indexes.[9] While its operation is strikingly similar to that of DBCC DBREINDEX, unlike DBCC INDEXFRAG it does not allow new fill factor to be specified.[9]

DBCC SHRINKDATABASE[edit]

This statement is used to reduce the size of a database.[10] This statement reduces the physical size of the database log file.[11][12] An alternate way to shrink a database is to use the commander ALTER DATABASE.[13]

DBCC SHRINKFILE[edit]

This statement is used to reduce the size of a data file or log file of a particular database.[14][15] The file could also be shrunk by using the SHRINKFILE attribute of the ALTER DATABASE command.[13]

DBCC UPDATEUSAGE[edit]

This statement is used to correct inaccuracies in the page and row statistics in the views.[16]

DBCC CLEANTABLE[edit]

This statement is used to remove spaces occupied by columns when they are removed.[17] This feature is not available with Microsoft SQL Server 2000 and has been newly introduced in Microsoft SQL Server 2005[17]

DBCC DROPCLEANBUFFERS[edit]

This statement is used to drop clean buffers from the buffer pool.[18] This feature is available with Microsoft SQL Server 2000 and in Microsoft SQL Server 2005[18]

DBCC FREEPROCCACHE[edit]

This statement is used to remove all elements from the procedure cache.[19] This feature is not available with Microsoft SQL Server 2000 and has been newly introduced in Microsoft SQL Server 2005[19]

DBCC INPUTBUFFER[edit]

This statement is used to display the last statement stored in the buffer.[20]

DBCC OPENTRAN[edit]

This statement is used to display information about the oldest open transaction.[21]

DBCC OUTPUTBUFFER[edit]

This statement is used to return the current value of the output buffer.[22]

DBCC PROCCACHE[edit]

This statement is used to display information about procedure cache.[23]

DBCC SHOWCONTIG[edit]

This statement is used to display fragmentation information[23]

DBCC SHOW_STATISTICS[edit]

This statement is used to show current distribution statistics[24]

DBCC SQLPERF[edit]

This statement is used to show transaction log statistics[25]

DBCC TRACESTATUS[edit]

This statement is used to display status of trace flags[26]

DBCC USEROPTIONS[edit]

This statement is used to return set as ACTIVE[27]

DBCC CHECKALLOC[edit]

This statement is used to checks whether every extent allocated by the system has been allocated and whether there are extents that have not been allocated.[28]

DBCC CHECKCATALOG[edit]

This statement is used to check for consistency between system tables[29] in the system catalog. It does so through cross-referencing checks.[28]

DBCC CHECKCONSTRAINTS[edit]

This statement is used to check integrity of specific constraints.[30]

DBCC CHECKDB[edit]

This statement is used to check integrity and allocation of specific objects in a database.[31] It also performs DBCC CHECKALLOC, DBCC CHECKTABLE and DBCC CHECKCATALOG in that particular order.[28]

DBCC CHECKFILEGROUP[edit]

This statement is used to check allocation and structural integrity of tables.[32]

DBCC CHECKIDENT[edit]

This statement is used to check identity value of specified table.[33]

DBCC CHECKTABLE[edit]

This statement is used to check the integrity of a table[34] and all the pages and structures which comprise the table.[28] Both physical and logical checks are performed in this case.[28] However, a PHYSICAL ONLY option can be used to check for physical consistency alone.[28]

DBCC NEWALLOC[edit]

DBCC NEWALLOC is almost similar to DBCC CHECKALLOC. This statement is not supported by recent versions.[35]

DBCC dllname (FREE)[edit]

This statement is used to unload a particular stored procedure DLL from memory.[35]

DBCC HELP[edit]

This statement is used to return syntax information.[36]

DBCC PINTABLE[edit]

This statement is used to mark a particular table to be pinned.[37]

DBCC ROWLOCK[edit]

This statement is used to enable Insert Row Locking (IRL) operations.[38]

DBCC TRACEOFF[edit]

This statement is used to disable a trace flag.[39]

DBCC TRACEON[edit]

This statement is used to turn on a specific trace flag.[40]

DBCC UNPINTABLE[edit]

This statement is used to mark a table as unpinned. In an unpinned table, the table pages in the cache could be easily removed.[41]

Running a Database Console Command[edit]

A database console command could be run from (i) the command window or (ii) query analyzer window.[42]

Advantages of Database Console Commands[edit]

Database Console Commands have a number of advantages. Their use is extremely essential in some instances

  • Occasionally, there have been bad allocations of database pages.[42]
  • Indexes could be destroyed or corrupted easily.[42]
  • There could misunderstandings on the part of the SQL server engine.[42]
  • There could be problems when a large number of updates need to be carried out.[42]
  • Individual pages may lose their optimal storage footprint.[42]

Notes[edit]

  1. ^ a b c "DBCC - Transact-SQL Reference (SQL Server 2000)". Microsoft Developer Network (MSDN). Retrieved 2008-06-20. 
  2. ^ Ogle, Pg 285
  3. ^ Rankins, Ray; Bertucci, Paul; Jensen, Paul (2003). Microsoft SQL Server 2000 unleashed. Sams Publishing. p. 365. ISBN 0672324679, ISBN 978-0-672-32467-3. 
  4. ^ "DBCC DBREINDEX, Transact-SQL Reference (SQL Server 2000)". Microsoft Developer Network (MSDN). Retrieved 2008-06-21. 
  5. ^ a b Dam, Pg 230
  6. ^ "DBCC DBREPAIR, Transact-SQL Reference (SQL Server 2000)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  7. ^ a b "DBCC DBREPAIR, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  8. ^ "DBCC INDEXDEFRAG, Transact-SQL Reference (SQL Server 2000)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  9. ^ a b Dam, Pg 236
  10. ^ Microsoft SQL Server 2000, Pg 142
  11. ^ Microsoft SQL Server 2000, Pg 398
  12. ^ Microsoft SQL Server 2000, Pg 402
  13. ^ a b Sack, Pg 568
  14. ^ "DBCC SHRINKFILE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  15. ^ Microsoft SQL Server 2000, Pg 367 - 370
  16. ^ "DBCC UPDATEUSAGE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  17. ^ a b "DBCC CLEANTABLE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  18. ^ a b "DBCC DROPCLEANBUFFERS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  19. ^ a b "DBCC FREEPROCCACHE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  20. ^ "DBCC INPUTBUFFER, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  21. ^ "DBCC OPENTRAN, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  22. ^ "DBCC OUTPUTBUFFER, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  23. ^ a b "DBCC PROCCACHE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  24. ^ "DBCC SHOWSTATISTICS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  25. ^ "DBCC SQLPERF, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  26. ^ "DBCC TRACESTATUS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  27. ^ "DBCC USEROPTIONS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  28. ^ a b c d e f Petkovic, Pg 403
  29. ^ "DBCC CHECKCATALOG, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  30. ^ "DBCC CHECKCONSTRAINTS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  31. ^ "DBCC CHECKDB, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  32. ^ "DBCC CHECKFILEGROUP, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  33. ^ "DBCC CHECKIDENT, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  34. ^ "DBCC CHECKTABLE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  35. ^ a b "DBCC NEWALLOC, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  36. ^ "DBCC NEWALLOC, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  37. ^ "DBCC PINTABLE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  38. ^ "DBCC ROWLOCK, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  39. ^ "DBCC TRACEOFF, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  40. ^ "DBCC TRACEON, Transact-SQL Reference (Suresh)". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  41. ^ "http://msdn.microsoft.com/en-us/library/aa258816(SQL.80).aspx". Microsoft Developer Network (MSDN). Retrieved 2008-06-23. 
  42. ^ a b c d e f Arthur Fuller (December 21, 2006). "Get out of a jam by using SQL Server's DBCC". 

References[edit]