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 :
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: January 13, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles