Home>Article>Database> What does the identity column in mysql mean and what is its use?

What does the identity column in mysql mean and what is its use?

anonymity
anonymity Original
2019-05-05 16:57:33 6986browse

The identification column is also called an auto-increasing column. There is an identification column attribute in the table field attribute of MySQL. Its function is to realize the self-increasing value of the table data. There is only one identification column in a table, and the step size can be set. Default is 1.

What does the identity column in mysql mean and what is its use?

What is the identity column?

The identification column is also called an auto-increasing column.

Meaning: You don’t need to manually insert values. The system provides default sequence values.

Features:

1. Does the identification column have to match the primary key? Not necessarily, but the requirement is a key

2. How many identity columns can a table have? At most one!

3. The type of the identification column can only be numerical.

4. The identification column can be set by SET auto_increment_increment=3; to set the step size

Set when creating the table Identity column AUTO_INCREMENT

DROP TABLE IF EXISTS tab_identity; CREATE TABLE tab_identity( id INT, NAME FLOAT UNIQUE AUTO_INCREMENT, seat INT ); TRUNCATE TABLE tab_identity; INSERT INTO tab_identity(id,NAME) VALUES(NULL,'john'); INSERT INTO tab_identity(NAME) VALUES('lucy'); SELECT * FROM tab_identity; SHOW VARIABLES LIKE '%auto_increment%';

Generated columns (including identity columns)is an important feature of DB2, used to automatically generate column values. The value of a generated column is not derived by an INSERT or UPDATE operation, but is automatically generated by DB2 based on predefinition. In the application, users can select different generated columns according to different needs to simplify the development or improvement of the application.

DB2's generated columns (GENERATED COLUMNS) are created by the GENERATED ALWAYS AS ... clause in the CREATE TABLE or ALTER TABLE statement.

The value of DB2's generated column is generated by a user-defined expression, and DB2 calculates the column value of the generated column based on the expression. When the application customizes generated columns, you need to specify the GENERATED AS EXPRESSION statement in the CREATE TABLE or ALTER TABLE statement.

The above is the detailed content of What does the identity column in mysql mean and what is its use?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what is mssql Next article:what is mssql