SQL Server cheat sheet

Share on:

######Reset auto-increment Key to 1

1DBCC CHECKIDENT ('[dbo].[ServiceIntegrations]', RESEED, 0) 
2GO

######Drop constraint with unknown name

1DECLARE @ObjectName NVARCHAR(100)
2SELECT @ObjectName = OBJECT_NAME([default_object_id]) FROM SYS.COLUMNS
3WHERE [object_id] = OBJECT_ID('[tableSchema].[tableName]') AND [name] = 'columnName';
4EXEC('ALTER TABLE [tableSchema].[tableName] DROP CONSTRAINT ' + @ObjectName)

Source: http://stackoverflow.com/questions/1430456/how-to-drop-sql-default-constraint-without-knowing-its-name