要設(shè)置字段自增,可以使用SQL語句中的AUTO_INCREMENT屬性。以下是使用不同數(shù)據(jù)庫系統(tǒng)的示例:
MySQL和MariaDB:
CREATE TABLE table_name (
column_name INT AUTO_INCREMENT,
other_columns,
PRIMARY KEY (column_name)
);
SQL Server:
CREATE TABLE table_name (
column_name INT IDENTITY(1,1),
other_columns,
PRIMARY KEY (column_name)
);
Oracle:
CREATE TABLE table_name (
column_name INT GENERATED ALWAYS AS IDENTITY,
other_columns,
PRIMARY KEY (column_name)
);
PostgreSQL:
CREATE TABLE table_name (
column_name SERIAL,
other_columns,
PRIMARY KEY (column_name)
);
請注意,這些示例中的"table_name"和"column_name"應(yīng)替換為實(shí)際的表名和列名。