Delete constraint for SQL Server

Source: Internet
Author: User

Delete a constraint using the SSMS database management tool

1, connect the database, select data Table-"Expand Key or Constraint-" Select the constraint to delete-"Right click-" SELECT Delete.

2. In the Delete object popup box-"click OK."

3, refresh the table-"Expand the Key or constraint-" view the results.

To delete a constraint using a T-SQL script

Grammar:

--Declaring database usage
Use database name;
Go

--Determine if a constraint exists, delete if it exists, do not delete if it does not exist
if exists (select * from sysobjects where name= constraint name)
ALTER TABLE name DROP CONSTRAINT constraint name;
Go

Example:

--Declaring database usage
Use TESTSS;
Go

--Determine if a constraint exists, delete if it exists, do not delete if it does not exist
if exists (select * from sysobjects where name= ' default1 ')
ALTER TABLE test1 drop constraint default1;
Go

Delete Constraint Summary

The deletion operation is irreversible, in the production database, regardless of whether the constraints are useful, you need to be careful to delete, the correct operation is to first backup and then delete.

SQL Server Delete constraint

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.