-5

I want to generate unique id in mysql before insert. Which concept is better for this . pls tell suggesstion to me.

I want to give auto increment with string.... Like create SKU id

3 Answers3

6

You could just have a primary key which is set on auto-increment, to get a unique id each time. This is done most of the times.

Pratik Bothra
  • 2,642
  • 2
  • 30
  • 44
0

You can set the primary key as auto-increment and this will work for you...

NoNaMe
  • 6,020
  • 30
  • 82
  • 110
  • Then before saving next record get the last id from DB, increase it by one( this will make new Id) and then save it to DB again :) – NoNaMe Feb 11 '13 at 12:15
  • Auto-increment works with int type, so you cant use it with strings... so you have to do this manually – NoNaMe Feb 11 '13 at 12:16
  • MySql does not allow auto-increment with Strings, Or you need to write some inner queries/procedures for that ... – NoNaMe Feb 11 '13 at 12:53
0

You can get the auto increment value like that, though, making the column A_I will increase your ID every insert.

Community
  • 1
  • 1
jeroenvisser101
  • 856
  • 10
  • 23