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