mysql中SERIAL和AUTO_INCREMENT有什么区别 [英] What is the difference between SERIAL and AUTO_INCREMENT in mysql

查看:243
本文介绍了mysql中SERIAL和AUTO_INCREMENT有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了两种自动增加mysql中id的方法.

I have come across two ways to increment the ids in mysql automatically.

一个是 SERIAL ,另一个是 AUTOINCREMENT .

因此,假设我想创建一个表myfriends. 我可以通过两种方式创建它:

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);

两者之间有什么区别?

OR

有谁能比其他人有优势?

Do anyone way has advantages over other ?

请帮助.

推荐答案

按照

SERIAL是BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE的别名.

SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.

因此,在创建对SERIAL PK的引用时要小心,因为该引用列必须是这种确切的类型.

So, be careful when creating a reference to a SERIAL PK, since that reference column has to be of this exact type.

这篇关于mysql中SERIAL和AUTO_INCREMENT有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆