1

I have a primary index on column URL but at the same time I need to have records with URL left blank which won't be permitted by the index.

I thought of a solution which is to add a new column called ID and make it auto-increment.

So I need to get the ID created with auto-increment on INSERT so that I stick it to column URL too. How can I do this?

If you can think of a better solution please tell

thanks

lisovaccaro
  • 32,502
  • 98
  • 258
  • 410
  • 1
    possible duplicate of [Get Auto Increment value with MySQL query](http://stackoverflow.com/questions/933565/get-auto-increment-value-with-mysql-query) – Ken White Sep 29 '11 at 02:12

2 Answers2

1

It is almost certainly better to use the mysql wrapper in your scripting language of choice to acquire the last insert id, but you can SELECT LAST_INSERT_ID(); to get it with mysql itself.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
0

The solution may depend on what other columns you have on your table. It will be hard for you to add an auto_increment column to a table that already has data. The process will be to create a new table with the new column added and add the data from the old table and then drop the old table and re-name the new one to the matching name.

Rasika
  • 1,980
  • 13
  • 19