SQL Delete Constraint

Source: Internet
Author: User

1 1) disables SQL for all table constraints2 Select 'ALTER TABLE'+Name+'nocheck constraint All'  fromsysobjectswhereType='U'3 4 2) Delete all table data for SQL5 Select 'TRUNCATE TABLE'+Name fromsysobjectswhereType='U'6 7 3) restore SQL for all table constraints8 Select 'ALTER TABLE'+Name+'Check Constraint all'  fromsysobjectswhereType='U'9 Ten 4) to delete a constraint for a field One Declare @name varchar( -) A --DF is the constraint name prefix - Select @name=B.name fromsyscolumns a,sysobjects bwherea.ID=object_id('Table name') andb.ID=A.cdefault andA.name='Field name'  andB.name like 'df%' - --Delete Constraint the Alter TableTable nameDrop constraint @name - --Add new default values and constraints for a field - ALTER TABLETable nameADD CONSTRAINT @name  DEFAULT(0) for [Field name]make changes to field constraints - --Delete Constraint + ALTER TABLETableName - Drop CONSTRAINTConstraint name + --Modify the properties of a column that already exists in the table (excluding constraints, but can be primary or incremented or unique) A ALTER TABLETableName at Alter columnColumn Nameint  not NULL - --constraints for adding columns - ALTER TABLETableName - ADD CONSTRAINTDf_tablename_ Column NameDEFAULT(0) forColumn Name - --Add scope constraint - Alter TableTableNameAdd  Check(Genderinch('M','F'))

SQL Delete Constraint

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.