SQL 2005 specific values to a column

  • Hi,

    I'm creating a table and want one of the fields to be populated with specific values.

    For example I want Shai field value to be either '1234' or '5678' (all other values will raise an error)

    Does any of you know how to do it?

  • You could do this with a check contraint. Here's a reference from BOL...

    http://msdn.microsoft.com/en-us/library/ms179491(SQL.90).aspx

    Basically you'd just do an alter Table Statement like so...

    Alter Table myTable

    ADD CONSTRAINT CK_mytable_Shai --or whatever meaningful name you choose

    CHECK (Shai = '1234' OR Shai = '5678')

    -Luke.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • Thanks.

    Checked that and it works

    Shai

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply