Unique Key Constraints

free php tutorials, php classes, php utilities, free tools
  • The UNIQUE constraint ensures that all values in a column are distinct.
  • primary key mus contain value
  • primary key column cannot contain NULL values.
  • A primary key can consist of one or more fields on a table. When multiple fields are used as a primary key, they are called a composite key.
  • Primary keys can be specified during alter table or create table

Example:

CREATE TABLE articles
(cat_id integer Unique ,
title varchar(30),
description varchar(30));

To create a UNIQUE constraint on the "article_id" column when the table is already created, use the following SQL:

ALTER TABLE articles
ADD UNIQUE (article_id)

Bookmark This Page