SQL Unique Constraints

Advertisements

Check Constraint in SQL Null Constraint in SLQ

SQL Unique Constraints

Unique Constraints does not allow duplicate values. You can apply unique constraints on more than one column in same table. You can apply unique constraints on more than one column in same table.

Advantage of Unique Constraints

This constraints allows to enter null value.

unique key

MySQL

	
create table employee
(
e_id number(3),
e_name varchar(15),
sal number(5),
unique e_id)
);

SQL Server / Oracle / MS Access

	
create table employee
(
e_id number(3) unique,
e_name varchar(15),
sal number(5)
);

Note: If you avoid the unique constraints property then it gives the following error messages "unique constraints scott sys-avoided"

SQL UNIQUE KEY constraint on ALTER TABLE:

This is the way to add unique key constraint on any column of table which table is already created, use following syntax;

MySQL / SQL Server / Oracle / MS Access:

	
ALTER TABLE employee
ADD UNIQUE (E_Id)

Naming of a UNIQUE constraint and apply on multiple column

To give name of unique key constraint and it apply on multiple column use given syntax;

MySQL / SQL Server / Oracle / MS Access

	
ALTER TABLE employee
ADD CONSTRAINT uc_EmployeeID UNIQUE (E_Id,LastName)

Drop Unique constraint

MySQL

	
ALTER TABLE employee
DROP INDEX uc_employeeID

SQL Server / Oracle / MS Access:

	
ALTER TABLE employee
DROP CONSTRAINT uc_employeeID

Check Constraint in SQL Null Constraint in SLQ

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements