如何实现一条sql语句插入多行数据

2025-03-04 04:55:35
推荐回答(3个)
回答1:

2种方案
1)
insert into tab1(fld1, fld2....fldn)
SELECT field1, field2....fieldn fom tab2 where xxxxx

2) insert into tab1(fld1, fld2....fldn) VALUES(1, 11, ....1111), (2, 22, ..., 2222), .....,(n, nn,...., nnnn)

回答2:

insert into tb (a,b,c,d)
select * from tbx where a<10

如果都是值也可以
insert into tb(a,b,c)
select 'a','b','c' union
select 'd','e','f' union
select 'x','y','z'

上面是三行数据

回答3:

insert into table_A
select * from table_B
注意:表a,b栏位数量和值类型要对应