What is the difference between SERIAL and AUTO_INCREMENT in mysql

前端 未结 3 716
青春惊慌失措
青春惊慌失措 2020-12-09 01:16

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

One is SERIAL and other is AUTOINCREMENT.

So Suppo

3条回答
  •  悲&欢浪女
    2020-12-09 01:45

    AUTO_INCREMENT is an attribute of a specific column of any numeric type (int or float), both signed and unsigned. When rows are inserted it automatically assigns sequential numbers, so you don't have to (e.g. by using LAST_INSERT_ID()). See http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

    SERIAL is an alias that combines column type casting (BIGINT specifically), AUTO_INCREMENT, UNSIGNED and other attributes for a specific column (see quote from docs below). See https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html

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

    SERIAL DEFAULT VALUE in the definition of an integer column is an alias for NOT NULL AUTO_INCREMENT UNIQUE.

提交回复
热议问题