Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3442822
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:42:58+00:00 2026-05-18T08:42:58+00:00

There appears to be at least two ways to add a default constraint using

  • 0

There appears to be at least two ways to add a default constraint using straight T-SQL. Am I correct that the only difference between the two below is that the second method specifically creates a name for the constraint, and the first method has one generated by SQL Server?

ALTER TABLE [Common].[PropertySetting] ADD DEFAULT ((1)) FOR [Active];
ALTER TABLE [Common].[PropertySetting] ADD CONSTRAINT [DF_PropertySetting_Active) DEFAULT ((1)) FOR [Active];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:42:59+00:00Added an answer on May 18, 2026 at 8:42 am

    Pretty much, yes for an ALTER TABLE

    You can add a columnn with default in one step for CREATE or ALTER too.

    ALTER TABLE dbo.TableName
        ADD bar varchar(100) CONSTRAINT DF_Foo_Bar DEFAULT ('bicycle');
    
    ALTER TABLE dbo.TableName
        ADD bar varchar(100) DEFAULT ('bicycle');
    

    As you noted, the system generates a name if one is not supplied. CONSTRAINT constraint_name is optional says MSDN. The same applies to any column or table CONSTRAINT


    If the column was already created, and you only want to add a (named) DEFAULT constraint, then use:

    ALTER TABLE dbo.TableName
        ADD CONSTRAINT DF_Foo_Bar DEFAULT 'bicycle' FOR FieldName;
    

    To have the system generate the DEFAULT constraint name (which will be of the form DF_{TableName}_{Column}_{8RandomChars}, e.g. DF_TableName_FieldName_12345678) then omit the CONSTRAINT <name> part, like so:

    ALTER TABLE dbo.TableName
        ADD DEFAULT 'bicycle' FOR FieldName;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It appears that ffmpeg now has a segmenter in it, or at least there
In the AS3 XML class there appears to be two ways of getting the
Edit: There appears to be at least two valid reasons why Smalltalkers do this
Is there an option to enable the drop down menu that appears when coding
Is there an event that fires in vb.net just before a contextMenuStrip appears when
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Consider the following two
In CruiseControl.NET there appears to be the same xsl stylesheets in the server directory
I am working on a .NET application where there appears to be a memory
From the answers to this question it appears there's a file somewhere on our
Is there any way to convert the image so it appears as a gray

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.