In SQL database, what should you do if you need to delete a table constraint? Here's how you can remove the SQL table constraint for your reference and hopefully help you.
1) Disable SQL for all table constraints
Select ' ALTER TABLE ' +name+ ' nocheck constraint all ' from sysobjects where type= ' U '
2) Delete SQL for all table data
Select ' TRUNCATE TABLE ' +name from sysobjects where type= ' U '
3) Restore SQL for all table constraints
Select ' ALTER TABLE ' +name+ ' check constraint all ' from sysobjects where type= ' U '
4) Delete a constraint for a field
DECLARE @name varchar (100)
--DF is the constraint name prefix
Select @name =b.name from syscolumns a,sysobjects b where a.id=object_id (' table name ') and B.id=a.cdefault and a.name= ' field name ' and B.N Ame like ' df% '
--Delete Constraint
ALTER TABLE name drop constraint @name
--Add new default values and constraints for the field
ALTER TABLE name ADD CONSTRAINT @name DEFAULT (0) for [field name] changes to field constraints
--Delete Constraint
ALTER TABLE TableName
Drop CONSTRAINT Constraint name
--Modify the properties of a column that already exists in the table (excluding constraints, but can be primary or incremented or unique)
ALTER TABLE TableName
ALTER column name int NOT NULL
--Adding a column constraint
ALTER TABLE TableName
ADD CONSTRAINT df_tablename_ Column name DEFAULT (0) for column name
--Add scope constraints
ALTER TABLE tablename Add check (Gender in (' M ', ' F '))
SQL Delete Constraint