Reputation: 588
I have a table with the following structure:
id | number | text
----------------------
1 | 1 | test
in which, id is my primary key with auto increment value. I want to make number as auto increment value too. Is it possible to have more than one auto increment column in one table?
Upvotes: 3
Views: 11068
Reputation: 4711
It is not possible.There can be only one auto-increment column and it must be defined as a key in MySQL.
But You can do it by using trigger
for detail go this link CREATE TRIGGER
Upvotes: 10
Reputation: 238
create trigger nameTrigger before insert on tables
for each row
begin
DECLARE newNumber unsigned default 0;
SELECT Max(number)+1 INTO newNumber FROM myTable WHERE id = new.id;
UPDATE myTable SET number = newNumber WHERE id = new.id;
end
Upvotes: 4