locked
Adding a Constraint. RRS feed

  • Question

  • I need to add a constraint to various Feilds in my table.

    On executing the following code I get Incorrect Syntax by Constraint. Please see attached code

    All help highly regarded

    R

    ALTER TABLE [Nop].[dbo].[Product]
    Alter Column PacksPerLayer int NOT NULL 
    CONSTRAINT CK_Product_PacksPerLayer DEFAULT '0'
    GO

    Friday, February 24, 2012 3:41 PM

Answers

  • ALTER TABLE [Nop].[dbo].[Product] ADD CONSTRAINT [CK_Product_PacksPerLayer] DEFAULT '0' FOR [PacksPerLayer]


    Jon

    • Proposed as answer by Naomi N Friday, February 24, 2012 4:56 PM
    • Marked as answer by RichIEvans Monday, February 27, 2012 11:24 AM
    Friday, February 24, 2012 4:01 PM

All replies

  • ALTER TABLE [Nop].[dbo].[Product]
    ADD [PacksPerLayer] INT NOT NULL 
    CONSTRAINT [CK_Product_PacksPerLayer] DEFAULT '0'


    Jon


    • Edited by Jon Gurgul Friday, February 24, 2012 3:55 PM
    • Proposed as answer by Naomi N Friday, February 24, 2012 4:56 PM
    Friday, February 24, 2012 3:53 PM
  • Column is already there I need to just add the constraint Is It possible?
    Friday, February 24, 2012 3:56 PM
  • ALTER TABLE [Nop].[dbo].[Product] ADD CONSTRAINT [CK_Product_PacksPerLayer] DEFAULT '0' FOR [PacksPerLayer]


    Jon

    • Proposed as answer by Naomi N Friday, February 24, 2012 4:56 PM
    • Marked as answer by RichIEvans Monday, February 27, 2012 11:24 AM
    Friday, February 24, 2012 4:01 PM