Aug 23, 2002 #1 dracuella Programmer Mar 10, 2001 4 DK Is there a way to have two columns as primary key in MYSQL and how would you reference it(alias)?
Aug 23, 2002 #2 cluelessNewbie Programmer Feb 13, 2002 42 US [tt] mysql> create table test (xx int not null, yy int not null, PRIMARY KEY mykey (xx, yy)); Not sure what you mean by the "reference" part but... mysql> insert into test values (1,2); Query OK, 1 row affected (0.00 sec) mysql> insert into test values (1,3); Query OK, 1 row affected (0.00 sec) mysql> insert into test values (1,4); Query OK, 1 row affected (0.00 sec) mysql> select * from test where xx = 1 and yy = 2; +----+----+ | xx | yy | +----+----+ | 1 | 2 | +----+----+ 1 row in set (0.00 sec) mysql> insert into test values (1,2); ERROR 1062: Duplicate entry '1-2' for key 1 [/tt] grrr... can't get the "tt" tags to work Upvote 0 Downvote
[tt] mysql> create table test (xx int not null, yy int not null, PRIMARY KEY mykey (xx, yy)); Not sure what you mean by the "reference" part but... mysql> insert into test values (1,2); Query OK, 1 row affected (0.00 sec) mysql> insert into test values (1,3); Query OK, 1 row affected (0.00 sec) mysql> insert into test values (1,4); Query OK, 1 row affected (0.00 sec) mysql> select * from test where xx = 1 and yy = 2; +----+----+ | xx | yy | +----+----+ | 1 | 2 | +----+----+ 1 row in set (0.00 sec) mysql> insert into test values (1,2); ERROR 1062: Duplicate entry '1-2' for key 1 [/tt] grrr... can't get the "tt" tags to work