Example of drop table if exists in SQL Server

IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = ‘Lesson36ProductCategorySource’ AND TABLE_SCHEMA = ‘Production’)
DROP TABLE [Production].[Lesson36ProductCategorySource];
GO

Advertisements

sql to find out who delete rows in SQLServer

FROM:http://stackoverflow.com/questions/2618179/is-there-something-like-if-not-exist-create-sequence-in-oracle-sql

DECLARE @TableName sysname
SET @TableName = 'dbo.Table_1'

SELECT
    u.[name] AS UserName
    , l.[Begin Time] AS TransactionStartTime
FROM
    fn_dblog(NULL, NULL) l
INNER JOIN
    (
    SELECT
        [Transaction ID]
    FROM 
        fn_dblog(NULL, NULL) 
    WHERE
        AllocUnitName LIKE @TableName + '%'
    AND
        Operation = 'LOP_DELETE_ROWS'
    ) deletes
ON  deletes.[Transaction ID] = l.[Transaction ID]
INNER JOIN
    sysusers u
ON  u.[sid] = l.[Transaction SID]