Archive for the ‘Nuggets’ Category

Get SQL Command Executing by SPID

Posted on November 25th, 2008 in Administering, Nuggets, Scripts and Queries | No Comments »

I’m sure there are other ways to do this but this is pretty easy:

DECLARE
 @SPID INT,
 @Handle binary(20),
 @retVal varchar(8000)

SET
 @SPID = 148

SELECT
 @Handle=sql_handle
FROM
 master..sysprocesses
WHERE spid = @SPID

SELECT
 SqlCommand=convert(varchar(8000), [text])
FROM
 ::fn_get_sql(@Handle)

References

Stored Procedure Naming Convention

Posted on November 19th, 2008 in Administering, Nuggets, Performance Tuning | No Comments »

Never use the sp_ prefix for a user-stored procedure. One reason is that it can make it hard to tell which sprocs are delivered and which are user-defined. Another is that if you prefix your sprocs with sp_, SQL searches for the prefix in the master db each time the procedure is called, before looking in the local database. Use usp_ instead.

From Microsoft eLearning Course 3595: Establishing Database Conventions and Standards for Microsoft® SQL Server™ 2005.

Quickly Get SQL Server Version, Edition and Update Level

Posted on October 19th, 2008 in Nuggets, Scripts and Queries | No Comments »

This query works on SQL Server 2000 and above:

USE [master]

SELECT
CAST(SERVERPROPERTY(’productversion’) AS VARCHAR) + ‘ - ‘
+ CAST(SERVERPROPERTY(’productlevel’) AS VARCHAR) + ‘ (’
+ CAST(SERVERPROPERTY(’edition’) AS VARCHAR) + ‘)’

SQL Server GO Keyword

Posted on October 16th, 2008 in Nuggets, T-SQL | No Comments »

You see the word GO in a lot of T-SQL scripts but do you actually know what it is or how to use it?

GO is actually not a part of T-SQL and is never passed to SQL Server. It is used by clients such as osql, sqlcmd, SSMS and Query Analyzer to control how commands are batched and sent to the server.

Read more about the GO keyword.

Adding LUNs to a SQL Server Cluster

Posted on October 10th, 2008 in Administering, Clustering, Nuggets, Windows Server 2003 | No Comments »

When you add a new LUN to a SQL Server cluster, you start by adding it as a partition under Windows Disk Management. However, SQL Server will not recognize the partition at this point. You must also add the disk resource to the dependency list for the SQL Server resource in the cluster.

The Difference Between the DATETIME and SMALLDATETIME Data Types

Posted on October 4th, 2008 in Data, Nuggets, SQL Server 2000, SQL Server 2005 | No Comments »

DATETIME requires 8 bytes of storage and stores dates from 1/1/1753 to 12/31/9999. It is accurate to about 3 milliseconds.

SMALLDATETIME requires only 4 bytes of storage. It can stores dates from 1/1/1900 to 6/6/2079 and is accurate to 1 minute.

If you’re not in the mood to wade through BOL, you can find a quick overview with a fair amount of detail on SQL Server datatypes here.

Performance: EXISTS vs LIKE

Posted on September 21st, 2008 in Nuggets, Performance Tuning, Querying, T-SQL | No Comments »

The EXISTS and NOT EXISTS operators can often use an index whereas the LIKE and NOT LIKE operators cause a table scan. This makes EXISTS and NOT EXISTS tend to be more efficient.

RAID for Log Files

Posted on September 21st, 2008 in Nuggets, Storage | No Comments »

Transaction log files should be optimized for sequential IO and secured against a single point of failure. Accordingly, RAID1 (mirroring) or RAID 10 (striping across mirrors) is recommended for transaction logs.

Technorati Profile