Developing By Me

Project Development and Design

UNIQUE INDEX

    Most databases use a standardized format for building UNIQUE keys. The standard syntax does work on most databases. The following table displays how to create a UNIQUE key in the different database engines.

 

SQL Syntax Description SQL Database
CREATE TABLE table_name (id INT NOT NULL,UNIQUE (id))

 

Creates a UNIQUE index when the table is created MySQL, PostgreSQL
CREATE TABLE table_name (id INT NOT NULL,name VARCHAR(50) NOT NULL,UNIQUE (id, name)

)

 

Creates a UNIQUE index when the table is created PostgreSQL
CREATE TABLE table_name (id INT NOT NULL UNIQUE)  Creates a UNIQUE index when the table is created PostgreSQL, SQL Server, Oracle
CREATE TABLE table_name (id INT NOT NULL,CONSTRAINT unique_index_name UNIQUE(id))

 

Creates a UNIQUE index when the table is created MySQL, SQL Server, Oracle
CREATE TABLE table_name (id INT NOT NULL CONSTRAINT unique_index_name UNIQUE)  Creates a UNIQUE index when the table is created PostgreSQL

 

%d bloggers like this: