Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. ALTER TABLE question

ALTER TABLE question

Scheduled Pinned Locked Moved Database
sql-serverquestiondatabasesysadmintools
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Corporal Agarn
    wrote on last edited by
    #1

    SQL Server 2008R2. Do all defaults need a constraint name? Why would you or would you not use a constraint name? Example of a SSMS created table script:

    ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [DF_MyTable_MyDateColumn] DEFAULT (getdate()) FOR [MyDateColumn]
    GO

    ALTER TABLE [dbo].[MyTable] ADD DEFAULT ((0)) FOR [MyBitColumn]
    GO

    Thanks

    S L 2 Replies Last reply
    0
    • C Corporal Agarn

      SQL Server 2008R2. Do all defaults need a constraint name? Why would you or would you not use a constraint name? Example of a SSMS created table script:

      ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [DF_MyTable_MyDateColumn] DEFAULT (getdate()) FOR [MyDateColumn]
      GO

      ALTER TABLE [dbo].[MyTable] ADD DEFAULT ((0)) FOR [MyBitColumn]
      GO

      Thanks

      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      From what I read on table constraints[^] It's to maintain backwards compatibility.

      Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

      C 1 Reply Last reply
      0
      • S Simon_Whale

        From what I read on table constraints[^] It's to maintain backwards compatibility.

        Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

        C Offline
        C Offline
        Corporal Agarn
        wrote on last edited by
        #3

        Thank you! As I have a tendensy to skim the definitions I miss things.

        1 Reply Last reply
        0
        • C Corporal Agarn

          SQL Server 2008R2. Do all defaults need a constraint name? Why would you or would you not use a constraint name? Example of a SSMS created table script:

          ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [DF_MyTable_MyDateColumn] DEFAULT (getdate()) FOR [MyDateColumn]
          GO

          ALTER TABLE [dbo].[MyTable] ADD DEFAULT ((0)) FOR [MyBitColumn]
          GO

          Thanks

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          It's always a good idea to use constraint names. Makes it easy to disable/drop a constraint.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups