Primary Key in SQL

Google Advertisements

Constraints in SQL Foreign Key Constraint

SQL Primary Key Constraints

Primary Key Constraints does not allow to enter duplicate as well as null values. This constraints is used to uniquely identify the record. You can not apply Primary Key constraints on more than one column in same table.

primary key in sql

A primary is a single column value used to identify a database record uniquely. It has the following attributes

  • A primary key cannot be NULL
  • A primary key value must be unique
  • The primary key values should rarely be changed
  • The primary key must be given a value when a new record is inserted

Advantage of Primary Key Constraints

Primary Key constraints does not allows to enter duplicate as well as null value.

Dis-Advantage of Primary Constraints

You can not apply this constraints on more than one column in same table.

SQL Server / Oracle / MS Access:

	
create table employee
(
e_id number(3) primary key,
ename varchar2(15),
sal number(5)
);

MySQL

	
create table employee
(
e_id number(3) primary key,
ename varchar(15),
sal number(5),
primary key (e_id)
);

primary 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 primary key (E_Id)

Drop Primary Key

MySQL

	
alter table employee
drop primary key

SQL Server / Oracle / MS Access:

	
ALTER TABLE employee
DROP CONSTRAINT pk_employeeID

Constraints in SQL Foreign Key Constraint

Google Advertisements

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

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

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

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs