Tuesday, June 11, 2013

Primary, unique, and key constraints

The following query creates a primary key for the id column:

CREATE TABLE IF NOT EXISTS products
(
  id INT UNIQUE AUTO_INCREMENT ,
  code INT NOT NULL ,
  name VARCHAR(25) NOT NULL ,
  quantity INT NOT NULL ,
  price DECIMAL(6,2) NOT NULL
) ;

So the question is does every unique column a primary key? No.

The reason is the primary key is a type of unique column. A more complete explanation is here.

No comments:

Post a Comment