SQL Server Deadlock Detection Script

use master
go
select
cntr_value
from
sysperfinfo
where
counter_name = ‘Number of Deadlocks/sec’
order by
cntr_value

 

Related error log messages might show up like that shown below:

Source  spid29s

Message Failure to send an event notification instance of type ‘DEADLOCK_GRAPH’ on conversation handle ‘{E96F2738-83CF-E111-8D19-00237D585B2C}’. Error Code = ‘8429’.

Truncate Requires Control Rights

Below is an output from a sql login session, the sql login account has select permissions, and attempts to truncate [quickly delete rows without logging each transaction] the table which has over 10,000 rows of data.

SQL Code

truncate table  [AdventureWorks2012].[dbo].[MyList]

Result ==========

Msg 1088, Level 16, State 7, Line 1 Cannot find the object “MyList” because it does not exist or you do not have permissions.

Solution

use [AdventureWorks2012]
GO
GRANT CONTROL ON [dbo].[MyList] TO [myuid]
GO

Result

6-5-2013 8-24-42 PM

In the above example, myuid is the name of the sql login account

 

SELECT INTO

This is a quick way to copy data from one table to the other. The other table will be created.

See example below, using the AdventureWorks2012 sample database from Microsoft

SELECT
[AddressID]       ,[AddressLine1]       ,[AddressLine2]       ,[City]       ,[StateProvinceID]       ,[PostalCode]       ,[SpatialLocation]       ,[rowguid]       ,[ModifiedDate]
into   MyList
FROM   [AdventureWorks2012].[Person].[Address]

6-5-2013 8-12-58 PM

Result (19614 row(s) affected)