mysql - 在特定列上应用自动增量 1 时出错

标签 mysql sql

我有一个表名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 中,这是全局设置,而不是表或列设置。

http://dev.mysql.com/doc/refman/5.0/en/replication-options-master.html#sysvar_auto_increment_increment

关于mysql - 在特定列上应用自动增量 1 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23416625/

相关文章:

mysql - 获取具有连接的人员的事件任务

mysqltuner - 需要临时表的排序

mysql - 使用 ProxySQL 缓存所有 SELECT

php - UPDATE Multiple ID 中的 PDO 准备语句

sql - 匹配值,但 SQL Server 中的新值出错

sql - RowNumber() 和 SUM() 在一个查询中

mysql - SQL:能否选择一列中的内容作为新表中的新列?

mysql - 错误代码: 1054 Unknown column 'try.tb_stores.division' in 'on clause'

mysql COUNT(*) 与 COUNT(DISTINCT col)

mysql - select 语句的 where 子句中的条件