Frequently used MSSQL Commands

 


-- MSSQL sleep command 
-- wait for a minute
WAITFOR DELAY '00:01'
-- wait for a second
WAITFOR DELAY '00:00:01'
-- wait for 200 ms
WAITFOR DELAY '00:00:00:200'



-- Transaction during DML 
BEGIN TRANSACTION

UPDATE Table SET Col2 = 'newValiue'
WHERE Col1 like 'mySearchCriteria'

IF (@@ROWCOUNT < 600 and @@ERROR = 0 )
BEGIN
	COMMIT TRANSACTION
	PRINT 'COMMIT'
END 
ELSE
BEGIN
	PRINT 'ROLLBACK'
	ROLLBACK TRANSACTION
END 



-- Server Name
SELECT @@SERVERNAME


-- Port- Find SQL Port Number 
SELECT local_tcp_port FROM   sys.dm_exec_connections
WHERE  session_id = @@SPID




--


Advertisements
This entry was posted in commands, SQL Server, Uncategorized and tagged , , , , , . Bookmark the permalink.

One Response to Frequently used MSSQL Commands

  1. Pingback: catalog | Blog for reference – Vijred

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s