WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL UNIQUE Constraint


SQL UNIQUE Constraint

The UNIQUE limitation interestingly recognizes each record in a database table.

The UNIQUE and PRIMARY KEY limitations both give an assurance to uniqueness for a section or set of columns.

A PRIMARY KEY imperative consequently has a UNIQUE requirement characterized on it.

Note that you can have numerous UNIQUE imperatives per table, however just a single PRIMARY KEY limitation per table.


SQL UNIQUE Constraint on CREATE TABLE

The following SQL makes a UNIQUE imperative on the "User_Id" section when the "Persons" table is created:

SQL Server/Oracle/MS Access:

Make TABLE Persons
(
User_Id int NOT NULL UNIQUE,
Username varchar(255) NOT NULL,
Secret key varchar(255),
Email Address varchar(255),
Telephone varchar(255)
)

MySQL:

Make TABLE Persons
(
User_Id int NOT NULL,
Username varchar(255) NOT NULL,
Secret key varchar(255),
Email varchar(255),
Telephone varchar(255),
Novel (P_Id)
)

To permit naming of a UNIQUE imperative, and for characterizing a UNIQUE requirement on different sections, utilize the accompanying SQL syntax:

MySQL/SQL Server/Oracle/MS Access:

Make TABLE Persons
(
User_Id int NOT NULL,
Username varchar(255) NOT NULL,
Secret key varchar(255),
Email varchar(255),
Telephone varchar(255),
Imperative uc_PersonID UNIQUE (User_Id,Username)
)

SQL UNIQUE Constraint on ALTER TABLE

To make a UNIQUE imperative on the "P_Id" section when the table is now made, utilize the accompanying SQL:

MySQL/SQL Server/Oracle/MS Access:

Change TABLE Persons
Include UNIQUE (User_Id)

To permit naming of a UNIQUE requirement, and for characterizing a UNIQUE imperative on various segments, utilize the accompanying SQL syntax:

MySQL/SQL Server/Oracle/MS Access:

Change TABLE Persons
Include CONSTRAINT uc_PersonID UNIQUE (User_Id,Username)

To DROP a UNIQUE Constraint

To drop a UNIQUE requirement, utilize the accompanying SQL:

MySQL:

Change TABLE Persons
DROP INDEX uc_PersonID

SQL Server/Oracle/MS Access:

Change TABLE Persons
DROP CONSTRAINT uc_PersonID