将自动递增ID添加到现有表中? [英] Add Auto-Increment ID to existing table?

查看:120
本文介绍了将自动递增ID添加到现有表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个预先存在的表,其中包含'fname','lname','email','password'和'ip'.但是现在我想要一个自动增量列.但是,当我输入:

I have a pre-existing table, containing 'fname', 'lname', 'email', 'password' and 'ip'. But now I want an auto-increment column. However, when I enter:

ALTER TABLE users
ADD id int NOT NULL AUTO_INCREMENT

我得到以下信息:

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

有什么建议吗?:)

推荐答案

尝试一下

ALTER TABLE `users` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY

这篇关于将自动递增ID添加到现有表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆