How to generate drop Unique Constraint scripts in SQL Server Database - SQL Server / TSQL Tutorial Part 99

Scenario:

You are working as SQL Server developer, you need to generate scripts to drop all Unique Constraints in SQL Server Database.

Solution:

The below syntax can be used to drop Unique Constraint on table.

Alter table [SchemaName].[TableName]
Drop Constraint [ConstraintName]

The below query can be used to generate drop Unique Constraints in SQL Server database.

SELECT 
Table_Schema,
Table_Name,
Constraint_Name,
'Alter table ['
+Table_Schema+'].['
+Table_Name+']'
+' Drop Constraint ['+Constraint_Name+']'
as DropUniqueConstraintQuery
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS 
WHERE CONSTRAINT_TYPE = 'UNIQUE'



Generate scripts to drop Unique Constraint in SQL Server Database


Video Demo : Generate Scripts for Drop Unique Constraints in SQL Server Database



No comments:

Post a Comment