Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wanting two columns for primary key?

Status
Not open for further replies.

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)?
 
[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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top