
将A表中的符合条件的数据查出,在新产生一条guid同时插入B表
sqlserver2005+以上案例:
--newid() 直接当及一列查询出来过滤到A表即可!
Insert into B表(字耐肢衫段1....)
select NEWID()[guid],* from 昌腔A表 where 过滤条件
如有问题可以追问,我饥猛当及时回答.
希望能帮到你!
两种方式
第一种
建表
create table b (id int,name varchar(10),price int)
insert into b values (1,'aa',100)
insert 散谈into b values (2,'bb',90)
insert into b values (3,'cc',101)
create table a (id varchar(64) default newid(),name varchar(10)) --注意a表的建表语句有默认值
先要将b表大于等于100的数据插入a中
insert into a(name) select name from b where price>=100
另一种方式,b表数据不变
c表
create 老掘扮table c (id varchar(64),name varchar(10))--此侍灶时id无默认值
执行
insert into c select newid(),name from b where price>=100
有三种磨笑办法:
sqlserver
insert into 表名瞎袜含 (字段名) values (newid())
oracle
insert into 表名(字段名) values (sys_guid())
mysql
insert into 表名(字段名) values(UUID())
你按你是什么数据库挑好旅着用即可。
insert B(col1,col2) select newid(),col3 from A where xxx