Add a Default to an Existing Table T-SQL

A quick implementation for adding a default value to an existing column in a table …the following example adds a default constraint “YourDefaultConstraintName” of 0 (zero) to the column “YourColumn” in the table “YourTable” …


ALTER TABLE YourTable
ADD  CONSTRAINT YourDefaultConstraintName
DEFAULT (0) FOR [YourColumn]

 

If the constraint already exists you will need to drop it first then add the constraint with the same name but with the new default value…Drop constraint sample code here …


ALTER TABLE YourTable DROP CONSTRAINT YourDefaultConstraintName

About AussieBICG

Connect with me here https://au.linkedin.com/in/aussiebicg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s