Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I create a new table for following query
create table employee_data
(
  emp_id int unsigned not null auto_increment primary key,
  f_name varchar(30),
  l_name varchar(20),
  age int,
  salary int
);

does not auto increment data. Please correct my sql query.
Posted
Updated 16-Feb-11 1:36am
v2

Have a look at the link below. It should work but you need to add ENGINE=MyISAM; at the end of your statement.
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html[^]

For InnoDB look here:
http://dev.mysql.com/doc/refman/5.1/en/innodb-auto-increment-handling.html[^]

Also check this out:
http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html#sqlmode_no_auto_value_on_zero[^]

Good luck!
 
Share this answer
 
Comments
Abhinav S 16-Feb-11 12:02pm    
Good links.
Hi,

You can use following query,
CREATE TABLE employee_data
(
emp_id int NOT NULL AUTO_INCREMENT,
f_name varchar(30),
l_name varchar(20),
age int,
salary int,
PRIMARY KEY (emp_id)
)

ALTER TABLE employee_data AUTO_INCREMENT=1;

Insert query will be
INSERT INTO Persons (f_name,l_name,age,salary) VALUES ('Brian','lara',25,5000)
Also you can check last inserted id by
mysql_insert_id()

Hope this will help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900