0

Anybody know where I can find the official MySql documentation on the PRIMARY KEY( param, param..) syntax that has several params to create one primary key?

All I could find on google was: https://dev.mysql.com/doc/refman/5.5/en/optimizing-primary-keys.html

Robert
  • 10,126
  • 19
  • 78
  • 130
  • possible duplicate of [Indexes and multi column primary keys](http://stackoverflow.com/questions/3048154/indexes-and-multi-column-primary-keys) – MaxZoom Jul 07 '15 at 22:31

3 Answers3

1

PRIMARY KEY as part of CREATE TABLE

http://dev.mysql.com/doc/refman/5.1/en/create-table.html

ryrysz
  • 907
  • 5
  • 11
0

The syntax is defined in the CREATE TABLE and ALTER TABLE commands:

http://dev.mysql.com/doc/refman/5.5/en/create-table.html http://dev.mysql.com/doc/refman/5.5/en/alter-table.html

Here are some simple examples:

CREATE TABLE invoice_lines (
    invoice_id int NOT NULL,
    product_id int NOT NULL,
    PRIMARY KEY (invoice_id, product_id)
);

ALTER TABLE invoice_lines
ADD PRIMARY KEY (invoice_id, product_id);
reaanb
  • 9,806
  • 2
  • 23
  • 37
0

Try this for the official manual:

http://dev.mysql.com/doc/refman/5.5/en/create-table.html

Also note that the order of the keys is important for those who want to use AUTO_INCREMENT and depends on the storage engine used for the table.

https://stackoverflow.com/a/2643986/3277192

Community
  • 1
  • 1