分类: Mysql/postgreSQL
2009-01-06 12:36:45
users表
SQL > select * from users;
ID NAME ADDRESS FLAG
--- ----------- --------------- ------
1 aaaaa aaaaaaaa123 1
2 bbbbb bbbbbbbb456 1
3 ccccc cccccbbb789 1
复制第一条记录到user表中
1.创建临时表
SQL> CREATE TABLE tmp_user AS select * from user where 1=2;
Table created.
2.复制第一条记录到临时表
SQL> INSERT INTO tmp_user SELECT * FROM user where id=1;
1 row inserted.
SQL > commit;
3.修改临时表记录[id字段为主键唯一标识]
SQL> update tmp_user set id=8;
1 row updated.
SQL > commit;
4.查看临时表
SQL > select * from tmp_user;
ID NAME ADDRESS FLAG
---- ----------- --------------- ------
8 aaaaa aaaaaaaa123 1
5.将临时表记录复制到原表中
SQL > INSERT INTO user SELECT * FROM tmp_user;
1 row inserted.
SQL > commit;
6.查看原表验证数据是否插入
SQL > select * from users;
ID NAME ADDRESS FLAG
---- ----------- --------------- ------
1 aaaaa aaaaaaaa123 1
2 bbbbb bbbbbbbb456 1
3 ccccc cccccbbb789 1
8 aaaaa aaaaaaaa123 1