In SQL, the AUTO_INCREMENT attribute is used to automatically generate a unique integer value when a new record is inserted into a table.
This is commonly used for creating primary key columns that need to have unique values for each record.
CREATE TABLE your_table_name ( column1 INT AUTO_INCREMENT PRIMARY KEY, column2 VARCHAR(50) );
column1 is set as an INT column with AUTO_INCREMENT and is also designated as the primary key for the table.
When we insert a new record into this table and do not provide a value for column1, SQL will automatically generate a unique integer value for it.
INSERT INTO department (department_name) VALUES ('HR');
we can also explicitly specify a value for the auto-increment column (perhaps for a specific reason), we can include that value in the INSERT statement:
INSERT INTO table_name (column1, column2) VALUES (33, 'column2_value');
Note: if we omit the column1 value, SQL will automatically generate the next available unique value.