MySQL Row Identifier: AUTO_INCREMENT Guide

In MySQL, there is no built-in ROWID column. However, a similar row identifier can be achieved by using an AUTO_INCREMENT column.

AUTO_INCREMENT is a column attribute used to create unique identifiers, allowing for the generation of unique increment values for each row in a table. This attribute can only be applied to columns of integer type.

Here is an example using an AUTO_INCREMENT column as a row identifier:

CREATE TABLE my_table (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50)
);

INSERT INTO my_table (name) VALUES ('John');
INSERT INTO my_table (name) VALUES ('Jane');
INSERT INTO my_table (name) VALUES ('Bob');

SELECT * FROM my_table;

Output result:

+----+------+
| id | name |
+----+------+
|  1 | John |
|  2 | Jane |
|  3 | Bob  |
+----+------+

In the example above, the id column is set as an AUTO_INCREMENT primary key column. The value of the id column will automatically increase with each row insertion. This allows each row to be uniquely identified by the id column.

bannerAds