create table a
(
uid int(8)
)
insert into test (uid) select 1;
insert into test (uid) select 2;
insert into test (uid) select 3;
insert into test (uid) select 4;
insert into test (uid) select 5;后面还有,而且其中也有漏的,不是连续的值
/*
得到这样的效果:
uid
1
2
3
4
5
*/
再建张表b
create table b
(
nid int(8)
)
insert into test (nid) select 0;
insert into test (nid) select 0;
insert into test (nid) select 0;
insert into test (nid) select 0;
insert into test (nid) select 0;后面还有,而且其中也有漏的,不是连续的值
/*
得到这样的效果:
nid
0
0
0
0
0
*/
通过update,使表b达到以下效果
/*
nid
1
2
3
4
5
*/
(
uid int(8)
)
insert into test (uid) select 1;
insert into test (uid) select 2;
insert into test (uid) select 3;
insert into test (uid) select 4;
insert into test (uid) select 5;后面还有,而且其中也有漏的,不是连续的值
/*
得到这样的效果:
uid
1
2
3
4
5
*/
再建张表b
create table b
(
nid int(8)
)
insert into test (nid) select 0;
insert into test (nid) select 0;
insert into test (nid) select 0;
insert into test (nid) select 0;
insert into test (nid) select 0;后面还有,而且其中也有漏的,不是连续的值
/*
得到这样的效果:
nid
0
0
0
0
0
*/
通过update,使表b达到以下效果
/*
nid
1
2
3
4
5
*/
只是我举得例子,真正的值没有规律,不知道该如何用变量替换,也可能我太菜,没想到替换方法。
因为其中一张表是ACCESS通过odbc导入到PhpMyAdmin里的,所以没有主键update b,(select uid from a) set b.nid=a.uid where b.nid=0;
我自己想的这语句没有成功,效果如下
/*
1
1
1
1
1
*/
只是update了第一个值,能改进吗?
增加自增字段两表,再替换
update b,uid a set b.nid=a.uid where a.id=b.id and b.nid=0;
alter table b add column b1 int auto_increment primary key;update a,b set b.nid=a.uid where a.a1=b.b1alter table q drop column a1;
alter table b drop column b1;
(
uid int(8)
)
insert into test (uid) select 1;
insert into test (uid) select 2;
insert into test (uid) select 3;
insert into test (uid) select 4;
insert into test (uid) select 5;