AUTOINCREMENT
Auto Increment allows a unique number to be generated when a new record is inserted into a table.
very often we would like the value of the primary key field to be created automatically every time a new record is inserted.
The syntax for MySQL:
NOTE: For MySQL, we use 'AUTO_INCREMENT' keyword to auto increment.
CREATE TABLE employee ( Emp_id INT(50) AUTO_INCREMENT NOT NULL, Name VARCHAR(100), Surname VARCHAR(100), Salary DEC(50), Dept_id INT(50) NOT NULL ); |
NOTE: For MS SQL we use 'IDENTITY' keyword to auto increment.
The syntax for MS SQL:
CREATE TABLE employee ( Emp_id INT(50) IDENTITY NOT NULL, Name VARCHAR(100), Surname VARCHAR(100), Salary DEC(50), Dept_id INT(50) NOT NULL ); |
After Execution:
Command(s) Completed Successfully.
Command(s) Completed Successfully.
No comments:
Post a Comment