If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > constraint on 2 columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-29-03, 20:48
poojajt poojajt is offline
Registered User
 
Join Date: Sep 2003
Location: CA
Posts: 38
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
Reply With Quote
  #2 (permalink)  
Old 10-29-03, 21:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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/
Reply With Quote
  #3 (permalink)  
Old 10-29-03, 21:32
poojajt poojajt is offline
Registered User
 
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

Quote:
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/
Reply With Quote
  #4 (permalink)  
Old 10-29-03, 21:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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


Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On