SQLzoo.net

CREATE TABLE with a composite primary key

MySQL

A composite key has more than one attribute (field). In this example we store details of tracks on albums - we need to use three columns to get a unique key - each album may have more than one disk - each disk will have tracks numbered 1, 2, 3...

The primary key must be different for each row of the table. The primary key may not contain a null.

Run the tidy code silently


Specific to MySQL
We must explicitly state that the components are NOT NULL.

Related links:

  • CREATE, DROP and ALTER