check constraints how can I make use of these

  • Hi, Happy Christmas to you,

    I am trying to set up a constraint that goes a bit like this

    If column1 is not null then column2 cannot be null either.

    Tried using constraint CHECK(column1 is not null and column2 is not null) this didnt work and does not have the if requirement.

    Any help or sources of good examples on this would be great - should I go down the route of writing scalar functions and checking against this function?

    Many Thanks for your help, Cheers,

    Oliver

  • i've seen this requirement before:

    check out the Check Constraint example i made here, aptly named "ThereCanBeOnlyOne"

    http://www.sqlservercentral.com/Forums/Topic789104-145-1.aspx

    it uses a check constraint to make sure zero or one of the columns has a value, raising an error if both; it would be trivial to change it so that ther emust be at elast one selection.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks i thought this might be the right way to go about it.

    Much appreciated.

    Oliver

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

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