SQL Server Deletes the default value constraint for a table

Source: Internet
Author: User

First isolate the default value constraint name for the field, and then delete the default value constraint based on the default value constraint name

Declare @constraintName varchar( $)Select @constraintName =B.name fromsyscolumns a,sysobjects bwherea.ID=object_id('Tb_kysubproject') andb.ID=A.cdefault andA.name='Final_belong_programme'  andB.name like 'df%'SELECT @constraintNameexec('ALTER TABLE tb_kysubproject drop constraint'+@constraintName)

Attention:

1.sql constraint prefix pk, UK, DF, CK, FK:

PK is primary key abbreviation, PRIMARY KEY constraint

UK is a unique key abbreviation, the only constraint

CK is a check abbreviation, checking constraints

FK is the foreign abbreviation, the primary foreign key relationship

DF is the default abbreviation, and defaults are constrained

2.syscolumns

cdefault :int the default value ID of the column.

ID:int the Table object ID that the column belongs to, or the stored procedure ID associated with the parameter.

Name :sysname The names of column names or procedure parameters.

3. object_id function

The function returns the ID value of the specified object

SQL Server Deletes the default value constraint for a table

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.