Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab. Download now (direct download link)
Thank this author by sharing:
By VPSD Gupta, 2013/05/24
Ever had the need to quickly execute a T-SQL script and generate SQL statements in SQL Server 2008 to drop a primary key, foreign keys, check constraints and/or defaults from a table ... Here is one script that would help you do this. You can pass few parameters and the script would generate all the required data with the alter statements. Create the SP in your database and you can run the SP using the following signature:
-- Generate SQL Statement to DROP the Primary Key of a table
EXEC usp_Drop_Table_Constraints @sConstraint_Type = 'PK', @sDB_Name = 'MY_DATABASE', @sTable_Name = 'MY_TABLE'
-- Generate SQL Statement to DROP the Foreign Keys of a table
EXEC usp_Drop_Table_Constraints @sConstraint_Type = 'FK', @sDB_Name = 'MY_DATABASE', @sTable_Name = 'MY_TABLE'
-- Generate SQL Statement to DROP the Check Constraints of a table
EXEC usp_Drop_Table_Constraints @sConstraint_Type = 'CK', @sDB_Name = 'MY_DATABASE', @sTable_Name = 'MY_TABLE'
-- Generate SQL Statement to DROP the Default Constraints of a table
EXEC usp_Drop_Table_Constraints @sConstraint_Type = 'DF', @sDB_Name = 'MY_DATABASE', @sTable_Name = 'MY_TABLE'
Generate all DDL statements for a given table (Create Table, PK, FK, Check Constraints, Defaults)
Check Constraint with Case Statement
New columnist Gregory Larsen used to not care what his objects were called until recently when he be...
This article from new author Oleg Netchaev describes the cursor-less script used to generate insert ...
Generates the merge statement for a given table.