Take a table to specify the default value for a column

Source: Internet
Author: User

Method One: Use system stored procedure sp_columns get
Sp_columns table_name, @column_name = ColumnName Returns the column_def of the result set is the default value of the field
Example: Get u_test table ID field C1 default value
Sp_columns u_test, @column_name = C1

Method Two: Obtain by system table syscolumns and syscomments
The Cdefault column in the syscolumns table is the default value ID, and its value corresponds to the syscomments table ID, syscomments the value of the table text column, which is the default value of the corresponding default value ID
Cases:
Select B.text
From syscolumns a LEFT join syscomments B on a.cdefault=b.id
where object_name (a.id) = ' u_test ' and a.name= ' C1 '

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.