我有一些桌子的桌子
我再添加一个“ id”字段,我想自动取值0,1,2 ... etc
什么命令执行此操作?
n
最佳答案
create table t(
a varchar(10) not null
,b varchar(10) not null
);
insert into t(a,b) values('a1', 'b1');
insert into t(a,b) values('a2', 'b2');
insert into t(a,b) values('a3', 'b3');
alter table t add id int not null auto_increment primary key;
select * from t;
+----+----+----+
| a | b | id |
+----+----+----+
| a1 | b1 | 1 |
| a2 | b2 | 2 |
| a3 | b3 | 3 |
+----+----+----+
关于mysql - 将值添加到mysql新字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4388105/