I have come across two ways to increment the ids in mysql automatically.
One is SERIAL and other is AUTOINCREMENT.
So Suppose i want to create a table myfriends.
I can create it in two ways like:
1)
mysql> create table myfriends(id int primary key auto_increment,frnd_name varchar(50) not null);
2)
mysql> create table myfriends(id serial primary key,frnd_name varchar(50) not null);
What is difference between the two ?
OR
Do anyone way has advantages over other ?
Please Help.
解决方案
As per the docs
SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.
So, be careful when creating a reference to a SERIAL PK, since that reference column has to be of this exact type.