SQL Server disables enabling triggers, FOREIGN KEY constraints

Source: Internet
Author: User

-- Disable the specified name trigger ALTER TABLE Tbname DISABLE TRIGGER trigname-- Restore the specified name trigger ALTER TABLE Tbname ENABLE TRIGGER trigname ----enable all triggers on a table ALTER TABLE Tbname enable TRIGGER all 

--Disable all triggers on all tables
exec sp_msforeachtable ' ALTER TABLE? DISABLE TRIGGER All '

--Enable all triggers on all tables
exec sp_msforeachtable ' ALTER TABLE? Enable TRIGGER all '

-- Add primary key ALTER TABLE TBNAME ADD constraint Pk_name primary key (COLUMN1,COLUMN2)-- add nonclustered primary key ALTER TABLE Tbname add Constraint Pk_name primary key nonclustered (COLUMN1,COLUMN2)-- Delete primary key ALTER TABLE tbname DROP constraint Pk_name 
-- Add foreign key ALTER TABLE TBNAME ADD constraint fk_name foreign key (fk_column) references Pk_tbname (pk_column)--  Delete foreign key ALTER TABLE tbname drop constraint fk_name

-- Enable or disable all foreign KEY constraints on the specified table   ALTER TABLE tbname  NOCHECK constraint all  alter TABLE tbname  CHECK constraint All-- view constraints Select from Sys.foreign_keys order by name

--Add UNIQUE constraints
ALTER TABLE TBNAME add constraint uq_colname unique (colname)

SQL Server disables enabling triggers, FOREIGN KEY constraints

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.