SQL Modify field Default value

Source: Internet
Author: User

First, SQL Modify field default value

    1. ALTER TABLE name DROP CONSTRAINT constraint name
    2. Description: Delete the original constraint for a table field
    3. ALTER TABLE name ADD constraint constraint first name default value for field name
    4. Description: Add a constraint for a table's field and specify a default value
    5. Go

Cases:

    1. ALTER TABLE t_ping DROP constraint Df_t_ping_p_c
    2. ALTER TABLE t_ping add constraint Df_t_ping_p_c DEFAULT ((2)) for P_c
    3. Go

Second, get the field default value

    1. Select B.text as Default field name (Random)
    2. From syscolumns a LEFT join syscomments B on a.cdefault=b.id
    3. where a.id=object_id (' table name ') and a.name= ' field name '

Description: syscolumns, syscomments for system table

Cases:

    1. Select B.text as Moren
    2. From syscolumns a LEFT join syscomments B on a.cdefault=b.id
    3. where a.id=object_id (' t_ping ') and a.name= ' P_c '

After getting the quotation marks, you can intercept the characters

SQL Modify field Default value

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.