我有一个表名article和一个列名articleid。我希望每次在表中输入数据时,articleid 列中的值应增加到 1。我正在尝试这样做。
ALTER TABLE article MODIFY COLUMN articleid INT auto_increment
但它会生成以下错误语句:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=1' at line 1
最佳答案
您的错误消息是
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=1' at line 1
但是您向我们展示的查询是
ALTER TABLE article MODIFY COLUMN articleid INT auto_increment
注意 =1
不在您向我们展示的查询中,因此您正在运行一些并非有意运行的代码。 ALTER TABLE
查询的语法看起来正确。
更新:要确保 MySQL 增量为 1,请将 MySQL 配置设置设置为 auto_increment_increment = 1
。请注意,在 MySQL 中,这是全局设置,而不是表或列设置。
关于mysql - 在特定列上应用自动增量 1 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23416625/