Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql SQL PRIMARY KEY Constraint

Related Tutorials


 
 

Share on Google+Share on Google+

SQL PRIMARY KEY Constraint

Advertisement
The PRIMARY KEY constraint is used to uniquely identifies each record in a database table.

SQL PRIMARY KEY Constraint

     

The PRIMARY KEY constraint is used to uniquely identifies each record in a database table. The Primary keys in a table contains a unique values. It should contain NULL values. The Table contain a primary key and each table have only primary key.

Understand with Example

The Tutorial illustrate an example to understand SQL PRIMARY KEY Constraint. In this example, we create a table 'Stu_Class_10.The create  statement is used to create a table 'Stu_Class_10'.The following SQL creates a PRIMARY KEY on the "Stu_Id" when the" Stu_Class_10" table is created.

Create Table Stu_Class_10

create table Stu_Class_10(
Stu_Id integer(2) NOT NULL,
Stu_Name varchar(15),
Stu_Class  varchar(10),
PRIMARY KEY(Stu_Id))

Insert data into Stu_Class_10

The insert into statement is used to add the records or rows to the table 'Stu_Class_10'. 

insert into Stu_Class_10 values(1,'Komal',10)
insert into Stu_Class_10 values(2,'Ajay',10)
insert into Stu_Class_10 values(3,'Rakesh',10)
insert into Stu_Class_10 values(4,'Bhanu',10)
insert into Stu_Class_10 values(5,'Santosh',10)

Stu_Class_10

Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 20, 2008

Related Tutorials

Discuss: SQL PRIMARY KEY Constraint   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com