Being day 24 of the DBCC Command month at SteveStedman.com, today’s featured DBCC Command is DBCC SHRINKDATABASE. When I first heard about DBCC Shrink Database (many years ago), I immediately thought “what a great feature, run this every night when the system load is low, and the database will be smaller, perform better, and all around be in better shape”. …

DBCC ShrinkDatabase Read more »

Here is a quick rundown on the T-SQL DATEPART function for SQL Server. DATEPART is used to pull a single part of a date/time element out as shown below. The following query uses DATEPART to extract the year from the datetime input. The following query uses DATEPART to extract the quarter from the datetime input. The following query uses DATEPART …

T-SQL DATEPART Explained Read more »

When creating a table you can specify IDENTITY with the following syntax: For example The IDENTITY property is valid for data types of the integer data type category, except for the bit data type, or decimal data type.  So how many rows can you insert into that table?  It depends on the data type used. BIGINT maximum value is 9,223,372,036,854,775,807 …

Are you wasting half the capacity of IDENTITY? Read more »

Queries with Common table expressions (CTE) are made up of two parts, the CTE part, and the SQL that references the CTE.  In preparation for SQL Saturday, the question came up of can you use an INSERT or UPDATE statement with a CTE.  Referring to the documentation I confirmed that using an insert or update inside of the CTE is …

CTE – With An Insert Statement Read more »

After creating and deploying the duplicate indexes report earlier today I discovered that although the report did exactly what it says, it didn’t do what I needed. The earlier  duplicate indexes report only found indexes that were an exact match on the columns.  And that is useful to track down, it didn’t point out indexes that were similar, but had additional columns. …

Free – Duplicate Indexes Report – Updated Read more »

Is it a good idea to run DBCC SHRINKDATABASE regularly? Download the sample file ShrinkSample. This article and samples apply to SQL Server 2005, 2008, and 2008R2. This really depends on a number of factors, but generally the answer is NO, it is not a good idea to run DBCC SHRINKDATABASE regularly. For the purpose of this article, I am …

Index Fragmentation and SHRINKDATABASE Read more »

Default Values and Computed Columns In SQL Server 2008, I was presented with the following error when attempting to create a table that has a default value that references other columns in the same table. Msg 128, Level 15, State 1, Line 6 The name “Subtotal” is not permitted in this context. Valid expressions are constants,  constant expressions, and (in …

MSG 128, Level 15, State 1 – not permitted in this context Read more »

The quick and easy way to determine how much memory your SQL Server is using is to look at the Task Manager on the server and find “sqlservr.exe” in the process list, and look at the “Mem Usage” column. But what if you are not on the server, or if you want to grab this information programmatically from an application, …

Query SQL Server 2008 Total Memory Usage Read more »