Database Console Commands (Transact-SQL)

Database Console Commands (Transact-SQL)

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]

Contents

Categories of DBCC Commands

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

DBCC DBREINDEX

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

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

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

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

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

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

DBCC CLEANTABLE

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

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

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

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

DBCC OPENTRAN

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

DBCC OUTPUTBUFFER

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

DBCC PROCCACHE

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

DBCC SHOWCONTIG

This statement is used to display fragmentation information[23]

DBCC SHOW_STATISTICS

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

DBCC SQLPERF

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

DBCC TRACESTATUS

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

DBCC USEROPTIONS

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

DBCC CHECKALLOC

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

DBCC CHECKCATALOG

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

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

DBCC CHECKDB

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

DBCC CHECKFILEGROUP

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

DBCC CHECKIDENT

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

DBCC CHECKTABLE

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, we can also use a PHYSICAL ONLY option to check for physical consistency alone.[28]

DBCC NEWALLOC

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

DBCC dllname (FREE)

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

DBCC HELP

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

DBCC PINTABLE

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

DBCC ROWLOCK

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

DBCC TRACEOFF

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

DBCC TRACEON

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

DBCC UNPINTABLE

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

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

Advantages of Database Console Commands

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 o 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

  1. ^ a b c "DBCC - Transact-SQL Reference (SQL Server 2000)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258281(SQL.80).aspx. Retrieved 2008-06-20. 
  2. ^ Ogle, Pg 285
  3. ^ Microsoft SQL Server 2000 unleashed. Sams Publishing. 2003. pp. 365. ISBN 0672324679, ISBN 9780672324673. 
  4. ^ "DBCC DBREINDEX, Transact-SQL Reference (SQL Server 2000)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258828(SQL.80).aspx. Retrieved 2008-06-21. 
  5. ^ a b Dam, Pg 230
  6. ^ "DBCC DBREPAIR, Transact-SQL Reference (SQL Server 2000)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258827(SQL.80).aspx. Retrieved 2008-06-23. 
  7. ^ a b "DBCC DBREPAIR, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/ms174416.aspx. Retrieved 2008-06-23. 
  8. ^ "DBCC INDEXDEFRAG, Transact-SQL Reference (SQL Server 2000)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258286(SQL.80).aspx. 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). http://msdn.microsoft.com/en-us/library/ms189493.aspx. 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). http://msdn.microsoft.com/en-us/library/ms188414.aspx. Retrieved 2008-06-23. 
  17. ^ a b "DBCC CLEANTABLE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/ms174418.aspx. Retrieved 2008-06-23. 
  18. ^ a b "DBCC DROPCLEANBUFFERS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/ms187762.aspx. Retrieved 2008-06-23. 
  19. ^ a b "DBCC FREEPROCCACHE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/ms174283.aspx. Retrieved 2008-06-23. 
  20. ^ "DBCC INPUTBUFFER, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258826(SQL.80).aspx. Retrieved 2008-06-23. 
  21. ^ "DBCC OPENTRAN, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258815(SQL.80).aspx. Retrieved 2008-06-23. 
  22. ^ "DBCC OUTPUTBUFFER, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258810(SQL.80).aspx. Retrieved 2008-06-23. 
  23. ^ a b "DBCC PROCCACHE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258820(SQL.80).aspx. Retrieved 2008-06-23. 
  24. ^ "DBCC SHOWSTATISTICS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258821(SQL.80).aspx. Retrieved 2008-06-23. 
  25. ^ "DBCC SQLPERF, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258819(SQL.80).aspx. Retrieved 2008-06-23. 
  26. ^ "DBCC TRACESTATUS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258797(SQL.80).aspx. Retrieved 2008-06-23. 
  27. ^ "DBCC USEROPTIONS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258811(SQL.80).aspx. 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). http://msdn.microsoft.com/en-us/library/aa258813(SQL.80).aspx. Retrieved 2008-06-23. 
  30. ^ "DBCC CHECKCONSTRAINTS, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258282(SQL.80).aspx. Retrieved 2008-06-23. 
  31. ^ "DBCC CHECKDB, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258278(SQL.80).aspx. Retrieved 2008-06-23. 
  32. ^ "DBCC CHECKFILEGROUP, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258818(SQL.80).aspx. Retrieved 2008-06-23. 
  33. ^ "DBCC CHECKIDENT, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258817(SQL.80).aspx. Retrieved 2008-06-23. 
  34. ^ "DBCC CHECKTABLE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258646(SQL.80).aspx. Retrieved 2008-06-23. 
  35. ^ a b "DBCC NEWALLOC, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258280(SQL.80).aspx. Retrieved 2008-06-23. 
  36. ^ "DBCC NEWALLOC, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258825(SQL.80).aspx. Retrieved 2008-06-23. 
  37. ^ "DBCC PINTABLE, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258284(SQL.80).aspx. Retrieved 2008-06-23. 
  38. ^ "DBCC ROWLOCK, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258812(SQL.80).aspx. Retrieved 2008-06-23. 
  39. ^ "DBCC TRACEOFF, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258288(SQL.80).aspx. Retrieved 2008-06-23. 
  40. ^ "DBCC TRACEON, Transact-SQL Reference (SQL Server 2005)". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258823(SQL.80).aspx. Retrieved 2008-06-23. 
  41. ^ "http://msdn.microsoft.com/en-us/library/aa258816(SQL.80).aspx". Microsoft Developer Network (MSDN). http://msdn.microsoft.com/en-us/library/aa258823(SQL.80).aspx. 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". http://articles.techrepublic.com.com/5100-10878_11-6142604.html. 

References


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Microsoft Data Access Components — MDAC redirects here. For other uses, see MDAC (disambiguation). MDAC (Microsoft Data Access Components) Microsoft Corporation s MDAC provides a uniform framework for accessing a variety of data sources on their Windows platform. Developer(s)… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”