Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Location
    CA
    Posts
    38

    Unanswered: constraint on 2 columns

    Hi,
    I have created a table 'n i need to place constraints on the columns such taht the combination of two columns should be unique.
    there is another combination of columns such that
    if account_name is populated either account_pop3 or account_imap shud be populated...the other one can be null.
    plz help me...
    Pooja

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    the first requirement is really straightforward, it's just a unique constraint on two columns

    the second requirement is a check constraint, which i don't believe mysql supports

    rudy
    http://r937.com/

  3. #3
    Join Date
    Sep 2003
    Location
    CA
    Posts
    38
    Hi Rudy,
    thanx a lot for that but i needed to know the syntax for the statement...i.e. the individual columns may've duplicate info but the combination of the columns needa be unique...so if u cud plz help me with the syntax.... 'n the second combination is not at all possible?
    Thank u.
    Pooja

    Originally posted by r937
    the first requirement is really straightforward, it's just a unique constraint on two columns

    the second requirement is a check constraint, which i don't believe mysql supports

    rudy
    http://r937.com/

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    the syntax? hmmm, how shall i put this politely...

    it's in the manual --> http://www.mysql.com/doc/en/CREATE_TABLE.html

    a specific example:

    create table yourtable
    ( id integer
    , foo varchar(3) not null
    , bar varchar(4) not null
    , unique index foobar (foo, bar)
    )

    as for the second, no, i do not think it's possible

    i could be wrong, though



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •