I am new to SQL, and I encountered an error when I tried to make a primary key to be Generated.
我是SQL的新手,当我尝试将主键设置为Generated时遇到错误。
I set customer_id attribute to be Primary Key, Not Null, Unique, and Generated so the system will auto generate the value for me.
我将customer_id属性设置为Primary Key,Not Null,Unique和Generated,以便系统自动为我生成值。
However, I encountered this error when I clicked on Generate selection.
但是,当我单击Generate selection时遇到此错误。
May I know how can I execute my sql statement to allow system to auto generate the primary key of customer_id?
我可以知道如何执行我的sql语句以允许系统自动生成customer_id的主键吗?
Thank you
2 个解决方案
#1
1
I don't know what the GUI is. But you want the column to be auto-incremented rather than generated (unless you are using MySQL 8+).
我不知道GUI是什么。但是您希望列自动递增而不是生成(除非您使用的是MySQL 8+)。
The resulting code could look like:
生成的代码可能如下所示:
id int auto_increment primary key
A primary key is automatically NULL
and UNIQUE
, so there is no need to declare those as well.
主键是自动NULL和UNIQUE,因此也不需要声明它们。
#2
1
Use auto increment(AI)
instead of auto generate
because auto generate
is not possible for a PK.
使用自动增量(AI)而不是自动生成,因为PK无法自动生成。
#1
1
I don't know what the GUI is. But you want the column to be auto-incremented rather than generated (unless you are using MySQL 8+).
我不知道GUI是什么。但是您希望列自动递增而不是生成(除非您使用的是MySQL 8+)。
The resulting code could look like:
生成的代码可能如下所示:
id int auto_increment primary key
A primary key is automatically NULL
and UNIQUE
, so there is no need to declare those as well.
主键是自动NULL和UNIQUE,因此也不需要声明它们。
#2
1
Use auto increment(AI)
instead of auto generate
because auto generate
is not possible for a PK.
使用自动增量(AI)而不是自动生成,因为PK无法自动生成。