I'm trying to create a table with two columns comprising the primary key in MySQL, but I can't figure out the syntax. I understand single-column PKs, but the syntax isn't the same to create a primary key with two columns.
+1
A:
Example:
CREATE TABLE `synthesis`.`INV_MasterItemList` (
`MasterItemList_ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`Customer_ID` INTEGER UNSIGNED NOT NULL,
`Model_ID` INTEGER UNSIGNED NOT NULL,
`Serial` VARCHAR(45) NOT NULL,
PRIMARY KEY (`MasterItemList_ID`),
UNIQUE INDEX `INDEX_UNIQUE`(`Customer_ID`, `Model_ID`, `Serial`)
)
Galwegian
2008-10-03 15:55:22
There's only one primary key in this example.
Christian Lescuyer
2008-10-03 16:09:30
+6
A:
CREATE TABLE table_name
(
c1 INT NOT NULL,
c2 INT NOT NULL,
PRIMARY KEY (c1, c2)
)
Neil Williams
2008-10-03 15:56:14
+1
A:
An example (from osCommerce) :
CREATE TABLE categories_description (
categories_id int DEFAULT '0' NOT NULL,
language_id int DEFAULT '1' NOT NULL,
categories_name varchar(32) NOT NULL,
PRIMARY KEY (categories_id, language_id),
KEY idx_categories_name (categories_name)
);
Christian Lescuyer
2008-10-03 15:57:15