Ask the Expert

Where are default constraint values stored?

In SQL Server, where are the values for the default constraint for a particular column stored? What is the column name that holds the value?

    Requires Free Membership to View

Implementing a default value for a column, if a value is not passed, is a great best practice when developing systems, because all of the logic is inline to the table. As such it is not necessary to write complex logic if a value is not passed and if a NULL value is not inserted.

To find the values it is necessary to query the syscolumns table for the particular column. The syscolumns table resides in the user database and stores one record for each column in a specific table. The syscolumns table also has a column named 'cdefault' that serves as an ID for the column and references syscomments. The syscomments table stores the definition of the default in the 'text' column.

For more information about defaults visit:
Creating and Modifying DEFAULT Definitions

 

For More Information

This was first published in April 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: