SQL Auto increment Primary Key

SQL Auto increment Primary Key is used to allow a unique number to be generated when a new record is inserted into a table.

Ads

SQL Auto increment Primary Key

     

SQL Auto increment Primary Key is used to allow a unique number to be generated when a new record is inserted into a table.

Understand with Example

The Tutorial illustrate an elaborative example from 'SQL Auto increment Primary Key'. To understand this example we use a query 'use mysqltutorialabc' that show the database is selected.

 

 

 

 

Create table employee_roseindia:

The create table employee_roseindia is used to create a table 'employee_roseindia' with required fieldname and data type. The following SQL statement is used to define the "Emp_id" to be an auto-increment primary key field in the table "employee_roseindia".

 Show Tables in datebase

Once the table is created ,the show tables shows you the list of tables in database.

Insert into Table :

The insert into adds the records or rows into the table'employee_roseindia'. If we don't insert any values into the primary key column, the auto_increment increment the value by 1 for each new records. 

insert into employee_roseindia values('1','Ranjan','Saurabh','5000');

insert into employee_roseindia values('2','Kumar','Satish','8000');

insert into employee_roseindia values('3','Kumar','Rajesh','10000');

insert into employee_roseindia values(' ','Saxena','Amit','15000');

To View the detail of Table employee_RoseIndia:

select * from employee_roseindia;

Output is displayed as below :

Advertisements

Ads
Share on Google+Share on Google+

SQL Auto increment Primary Key

Posted on: January 13, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: SQL Auto increment Primary Key  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
DHIRAJ
March 27, 2011
AUTO INCREMENT IN SQL WITH A EXAMPLE

I see to Auto Increment on the net and I like but not any example on net. If you receipt my message so pleases send a example to me............. I wait............ Thanks
Shailu
December 27, 2011
adding auto_increment

Hi, is it possible to add Auto_Increment using alter query

Ads

 

Ads