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]
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 Micrcosoft 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 not available with Micrcosoft SQL Server 2000 and has been newly introduced 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 Micrcosoft 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.0 1.1 1.2 "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.
- ↑ Ogle, Pg 285
- ↑ Microsoft SQL Server 2000 unleashed. Sams Publishing. 2003. pp. 365. ISBN 0672324679, ISBN 9780672324673.
- ↑ "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.0 5.1 Dam, Pg 230
- ↑ "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.0 7.1 "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.
- ↑ "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.0 9.1 Dam, Pg 236
- ↑ Microsoft SQL Server 2000, Pg 142
- ↑ Microsoft SQL Server 2000, Pg 398
- ↑ Microsoft SQL Server 2000, Pg 402
- ↑ 13.0 13.1 Sack, Pg 568
- ↑ "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.
- ↑ Microsoft SQL Server 2000, Pg 367 - 370
- ↑ "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.0 17.1 "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.0 18.1 "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.0 19.1 "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.
- ↑ "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.
- ↑ "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.
- ↑ "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.0 23.1 "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. Cite error: Invalid
<ref>
tag; name "msdn_dbcc_dbproccache" defined multiple times with different content - ↑ "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.
- ↑ "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.
- ↑ "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.
- ↑ "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.0 28.1 28.2 28.3 28.4 28.5 Petkovic, Pg 403
- ↑ "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.
- ↑ "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.
- ↑ "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.
- ↑ "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.
- ↑ "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.
- ↑ "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.0 35.1 "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.
- ↑ "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.
- ↑ "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.
- ↑ "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.
- ↑ "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.
- ↑ "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.
- ↑ "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.0 42.1 42.2 42.3 42.4 42.5 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
- Microsoft SQL Server 2000 Database Design and Implementation. Microsoft Press
- Designing SQL Server 2000 Databases for .NET Enterprise Servers. Syngress. 2001. pp. 285–286. ISBN 1928994199, ISBN 9781928994190.
- Mastering Microsoft SQL Server 2005. John Wiley and Sons. 2006. ISBN 0782143806, ISBN 9780782143805.
- Dušan Petkovic (2008). Microsoft SQL Server 2008: A Beginner's Guide: A Beginner's Guide. McGraw-Hill Professional. ISBN 0071546383, ISBN 9780071546386.
- Sajal Dam (2004). SQL Server Query Performance Tuning Distilled. Apress. ISBN 1590594215, ISBN 9781590594216.
If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...