Will this relate the primary keys to one another or just create primary keys on the columns.
Ie: Create table test (column1 int(11) not null, column2 int(11) not null, primary key (column1, column2) ) Then could you... Insert into test values ("1","2") Insert into test values ("1","3") Note that the combination of the two columns represents a distinct value but column 1 is the same value in both inserts. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Bill Adams Sent: Monday, November 12, 2001 12:05 PM To: Brendin Cc: [EMAIL PROTECTED] Subject: Re: primary key based on unique value for two columns Brendin wrote: > I would like to have a table that has a primary key defined on a > combination of two columns in the table. In other words a unique key > based upon the values in two columns. > > I don't think I am able to do this in mysql. I think you can only > have a primary key on one column and not on a combination of columns. > If I am wrong please correct me. At least in 3.23.x (x>?) and higher you CAN have a primary key on multiple columns. > I am looking for work arounds. I have thought of one. That would be > to concatenate the columns and use a field terminator such as a - to > separate the values or (columns) in the single column. Then you could > use string functions to parse the columns. Ex: [snip] There is a maximum key lenth so if you have two char(255) columns you might need to do something like: ALTER TABLE table ADD PRIMARY KEY( char_col1(100), char_col2(100)); However, this also means that the combination of the first 100 chars from each column must be unique. b. --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php