Getting started with Microsoft SQL ServerOVER ClausePIVOT / UNPIVOTDatabase SnapshotsRetrieve information about the databaseThe STUFF FunctionFOR XML PATHCursorsJoinCommon Table ExpressionsMove and copy data around tablesDatesLimit Result SetRetrieve Information about your InstanceWith Ties Option VariablesJSON in Sql ServerWindow functionsPartitioningStored ProceduresGROUP BYGenerating a range of datesCOALESCESplit String function in Sql ServerINSERT INTOCREATE VIEWString FunctionsResource GovernorORDER BYWHILE loopSystem database - TempDbMigrationPrimary KeysMERGEFull-Text IndexingFOR JSONSELECT statementDBMAILIndexQueries with JSON dataStoring JSON in SQL tablesOPENJSONRanking FunctionsTriggerConverting data typesNULLsTransaction isolation levelsAdvanced optionsIF...ELSETRY/CATCHData TypesUser Defined Table TypesTable Valued ParametersIn-Memory OLTP (Hekaton)Temporal TablesInsertSequencesSCOPE_IDENTITY()ViewsUse of TEMP TableScheduled Task or JobIsolation levels and lockingSorting/ordering rowsPrivileges or PermissionsForeign KeysSQLCMDFile Groupcross applyBasic DDL Operations in MS SQL ServerComputed ColumnsUNIONSubqueriesLast Inserted IdentityCLUSTERED COLUMNSTOREParsenameInstalling SQL Server on WindowsAggregate FunctionsQuerying results by pageSchemasBackup and Restore DatabaseTransaction handlingNatively compiled modules (Hekaton)Database permissionsSpatial DataDynamic SQLPaginationQuery HintsModify JSON textRow-level securityDynamic data maskingExport data in txt file by using SQLCMDEncryptionManaging Azure SQL DatabaseCommon Language Runtime IntegrationDelimiting special characters and reserved wordsCASE StatementDBCCBULK ImportQuery StoreService brokerAnalyzing a QueryMicrosoft SQL Server Management Studio Shortcut KeysPermissions and SecurityPHANTOM readFilestreamDrop KeywordString Aggregate functions in SQL ServerSQL Server Evolution through different versions (2000 - 2016)SQL Server Management Studio (SSMS)Logical FunctionsDynamic SQL PivotAlias Names in Sql Serverbcp (bulk copy program) Utility

DBCC

Other topics

DBCC statement

DBCC statements act as Database Console Commands for SQL Server. To get the syntax information for the specified DBCC command use DBCC HELP (...) statement.

The following example returns all DBCC statements for which Help is available:

DBCC HELP ('?');  

The following example returns options for DBCC CHECKDB statement:

DBCC HELP ('CHECKDB'); 

DBCC maintenance commands

DBCC commands enable user to maintain space in database, clean caches, shrink databases and tables.

Examples are:

DBCC DROPCLEANBUFFERS 

Removes all clean buffers from the buffer pool, and columnstore objects from the columnstore object pool.

DBCC FREEPROCCACHE
-- or
DBCC FREEPROCCACHE (0x060006001ECA270EC0215D05000000000000000000000000);

Removes all SQL query in plan cache. Every new plan will be recompiled: You can specify plan handle, query handle to clean plans for the specific query plan or SQL statement.

DBCC FREESYSTEMCACHE ('ALL', myresourcepool); 
-- or
DBCC FREESYSTEMCACHE;

Cleans all cached entries created by system. It can clean entries o=in all or some specified resource pool (myresourcepool in the example above)

DBCC FLUSHAUTHCACHE 

Empties the database authentication cache containing information about logins and firewall rules.

DBCC SHRINKDATABASE (MyDB [, 10]); 

Shrinks database MyDB to 10%. Second parameter is optional. You can use database id instead of name.

DBCC SHRINKFILE (DataFile1, 7); 

Shrinks data file named DataFile1 in the current database. Target size is 7 MB (tis parameter is optional).

DBCC CLEANTABLE (AdventureWorks2012,'Production.Document', 0) 

Reclaims a space from specified table

DBCC validation statements

DBCC commands enable user to validate state of database.

ALTER TABLE Table1 WITH NOCHECK ADD CONSTRAINT chkTab1 CHECK (Col1 > 100);  
GO  
DBCC CHECKCONSTRAINTS(Table1);  
--OR
DBCC CHECKCONSTRAINTS ('Table1.chkTable1');  

Check constraint is added with nocheck options, so it will not be checked on existing data. DBCC will trigger constraint check.

Following DBCC commands check integrity of database, table or catalog:

DBCC CHECKTABLE tablename1 | tableid
DBCC CHECKDB databasename1 | dbid
DBCC CHECKFILEGROUP filegroup_name | filegroup_id | 0
DBCC CHECKCATALOG databasename1 | database_id1 | 0

DBCC informational statements

DBCC commands can show information about database objects.

DBCC PROCCACHE

Displays information in a table format about the procedure cache.

DBCC OUTPUTBUFFER ( session_id [ , request_id ])  

Returns the current output buffer in hexadecimal and ASCII format for the specified session_id (and optional request_id).

DBCC INPUTBUFFER ( session_id [ , request_id ])  

Displays the last statement sent from a client to an instance of Microsoft SQL Server.

DBCC SHOW_STATISTICS ( table_or_indexed_view_name , column_statistic_or_index_name)

DBCC Trace commands

Trace flags in SQL Server are used to modify behavior of SQL server, turn on/off some features. DBCC commands can control trace flags:

The following example switches on trace flag 3205 globally and 3206 for the current session:

DBCC TRACEON (3205, -1); 
DBCC TRACEON (3206);

The following example switches off trace flag 3205 globally and 3206 for the current session:

DBCC TRACEON (3205, -1); 
DBCC TRACEON (3206);

The following example displays the status of trace flags 2528 and 3205:

DBCC TRACESTATUS (2528, 3205);  

Contributors

Topic Id: 7316

Example Ids: 24310,24306,24307,24308,24309

This site is not affiliated with any of the contributors.