How to use auto-increment primary key in MySQL?
In MySQL, you can use the AUTO_INCREMENT keyword to define an automatically incrementing primary key field. For example, here is an example of defining an auto-increment primary key when creating a table:
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL
);
In the example above, the “id” field is defined as an auto-increment primary key and serves as the primary key for the table. Each time a new record is inserted into the table, the value of the “id” field will automatically increase, ensuring that each record has a unique primary key value.