#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Help with a if statement


    hey guys, i'm new here and am stuck with a bit of sql.

    i've got a project and im wondering whether it is possible to create an if statement that says something like

    "If column A is NOT NULL then column B cannot be NULL"

    would I have to do this as a trigger or a constraint? any help would be greatly appreciated!

    cheers
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,788
    Rep Power
    349
    Code:
    CREATE TABLE foobar
    (
       foo integer,
       bar integer,
       constraint check_not_null check (foo is null or (foo is not null and bar is not null))
    );
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0
    thanks, works fine

IMN logo majestic logo threadwatch logo seochat tools logo