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

I have tried to alter a table to add a index column by using auto increment like this;
SQL
alter table donordetails add SlNo int not null auto_increment first ,add unique key(SlNo);


It is working, but the incrementing of the value is not consecutive, some times random value is coming, so what to do ?

any methode something like identity(1,1) in mssql

Regards
Ginnas
Posted
Updated 25-Mar-13 4:47am
v2
Comments
PIEBALDconsult 25-Mar-13 11:00am    
auto_increment is evil, don't use it.
CHill60 25-Mar-13 12:26pm    
What would you suggest as an alternative?
ginnas 25-Mar-13 11:10am    
thanks

but tell me the proper one to use in mysql please

Thanks
Ginnas
CHill60 25-Mar-13 12:19pm    
Under what circumstances does random value get assigned ... do you have any zeroes in s1No? Are you inserting then deleting lots of rows? Finally do you still get the problem if you define s1No as unsigned or bigint?
ginnas 25-Mar-13 22:49pm    
thanks

i will try to clear the situation to you, what is happening means while i am insering a value continously the auto increment column should be increment consecutivly but sometimes it is not consecutive like this suppose ....401,402,403,406 so inbetween some valuelike 404,405 is missing thats the problem

Thanks
Ginnas

1 solution

Try

SQL
PRIMARY KEY (`SlNo`)
 
Share this answer
 
Comments
ginnas 25-Mar-13 22:44pm    
thanks

but in my table already one primary key is assigned
then what to do?

Thanks

Ginnas

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