如果我尝试从AUTO_INCREMENT列中删除PRIMARY KEY约束会发生什么?
示例
假设我们有一个名为“Accounts”的表,具有以下描述 −
mysql> Describe accounts; +--------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+----------------+ | Sr | int(10) | NO | PRI | NULL | auto_increment | | Name | varchar(20) | YES | | NULL | | | amount | int(15) | YES | | NULL | | +--------+-------------+------+-----+---------+----------------+ 3 rows in set (0.10 sec)
它具有一个带有AUTO_INCREMENT和PRIMARY KEY定义的字段'Sr'。现在,如果我们尝试删除这个PRIMARY KEY,MySQL将抛出以下错误-
mysql> Alter table Accounts DROP PRIMARY KEY; ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
以上就是如果我尝试从AUTO_INCREMENT列中删除PRIMARY KEY约束会发生什么?的详细内容,更多请关注其它相关文章!