Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --To Disable a Constraint at DB level
- EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
- --Write the code to DROP tables
- DROP TABLE TABLENAME
- DROP TABLE TABLENAME
- DROP TABLE TABLENAME
- --To Enable a Constraint at DB level
- EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
- --Checks the Status of Constraints
- SELECT (CASE
- WHEN OBJECTPROPERTY(CONSTID, 'CNSTISDISABLED') = 0 THEN 'ENABLED'
- ELSE 'DISABLED'
- END) AS STATUS,
- OBJECT_NAME(CONSTID) AS CONSTRAINT_NAME,
- OBJECT_NAME(FKEYID) AS TABLE_NAME,
- COL_NAME(FKEYID, FKEY) AS COLUMN_NAME,
- OBJECT_NAME(RKEYID) AS REFERENCED_TABLE_NAME,
- COL_NAME(RKEYID, RKEY) AS REFERENCED_COLUMN_NAME
- FROM SYSFOREIGNKEYS
- ORDER BY TABLE_NAME, CONSTRAINT_NAME,REFERENCED_TABLE_NAME, KEYNO
- SELECT *
- FROM sys.foreign_keys
- WHERE referenced_object_id = object_id('dbo.Tablename')
- ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint
- DROP TABLE TABLENAME
- select concat("alter table ", table_name, " drop ", constraint_type ," ", constraint_name, ";")
- from information_schema.table_constraints
- where table_name like 'somefoo_%'
- and
- constraint_type <> "PRIMARY KEY";
- ALTER TABLE Orders DROP FOREIGN KEY fk_PerOrders;
- DROP TABLE Orders;
- DROP TABLE Orders;
- DROP TABLE Order_lines;
- DROP TABLE Order_lines;
- DROP TABLE Orders;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement