The Third Project - Obscure T-SQL commands
Ok so maybe this isn't a project so much as a topic. This will be the first in a series of post dealing with obscure t-sql commands from SQL Server 2000 thru 2008 that I find, that may be useful to other people. Hopefully this will be a weekly series and allow me the opportunity to find new commands or find out more about commands I thought I knew. This series is not meant to tell you everything about a command will do this in a much more in-depth manner than these post, but I will bring to light commands you might not even now exist. This week I have two commands one common one not so common but both very useful.
GO, yes thats it, we've all used it to break up statements but did you know you can add parameters to the GO command (Go is not a T-SQL Command it is a command recognized by the sqlcmd or osql utility), say GO 5 this will cause the statement block above to execute five times. I saw this on a QotD over on SQLServerCenteral.com (October 8th 2007 - What does this do?)
Example:
select rand() random
select count(*) from sysobjects
GO 5
The next obscure T-SQL command is WAITFOR this command allows you to put a delay into your sql code. This command allows you to delay for a certain amount of time or until a certain time occurs. The command has two key words associated with it DELAY for an amount of time specific duration and TIME for a specific time to run the command following it.
The example below will for 5 seconds in between the first select and the second.
Example:
select getdate() priorWAITFORDate
WAITFOR DELAY '00:05'
select getdate() postWAITFORDate
As always can provide additional and more in-depth command documentation.