要設置字段自增,可以使用SQL語句中的AUTO_INCREMENT屬性。以下是使用不同數據庫系統的示例:
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"應替換為實際的表名和列名。