在sql server 里用sql语句如何复制多行记录呀

chenhw_08 2009-04-26 10:27:56
在sql server 里用sql语句如何复制多行记录呀
...全文
561 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
步慢生错 2009-04-26
  • 打赏
  • 举报
回复
其实很简单嘛
insert into 目标表(列名) select 列名 from 源表 where xxxx
xk35860368qqqq 2009-04-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hecong875 的回复:]
SQL code
-- select * from Mst_Restaurants
-- delete Mst_Restaurants
-- sp_help Mst_Restaurants
declare @Count int
declare @OverCount int
declare @DateType int

select @Count = 1

select @DateType = 101

select @OverCount = 100000

while @Count < @OverCount
Begin
insert into Mst_LivingService
(
ProvinceNo,
CityNo,
ServerName,
BusinessesName,
BusChineseCode,
BranchN…
[/Quote]

注解都没有要楼主他正麽看啊 ·~

teerhu 2009-04-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zsuswy 的回复:]
如楼上的
insert into 源table select * from 目标table where ........
或者
select into 目标table from 源table where ........
[/Quote]
支持
中年秃头大叔 2009-04-26
  • 打赏
  • 举报
回复
例如:要把a表中符合条件的数据复制到b表中
insert into b select * from a where ..

例a表:id num
b表id num
insert into b select * from a where a.id<=5//where 语句可换成自己需要的。
zsuswy 2009-04-26
  • 打赏
  • 举报
回复
如楼上的
insert into 源table select * from 目标table where ........
或者
select into 目标table from 源table where ........
chen_ya_ping 2009-04-26
  • 打赏
  • 举报
回复
先把要复制的数据选出来,然后再插入这个表中。
hecong875 2009-04-26
  • 打赏
  • 举报
回复

-- select * from Mst_Restaurants
-- delete Mst_Restaurants
-- sp_help Mst_Restaurants
declare @Count int
declare @OverCount int
declare @DateType int

select @Count = 1

select @DateType = 101

select @OverCount = 100000

while @Count < @OverCount
Begin
insert into Mst_LivingService
(
ProvinceNo,
CityNo,
ServerName,
BusinessesName,
BusChineseCode,
BranchName,
BranchChineseCode,
Aliases,
Phone,
Address,
MsgType,
AreaNo,
PostCode,
OwnedArea,
LandmarkBuilding,
PopularityIndex,
BusinessDescribe,
BusinessFeatures,
StartTime,
EndTime,
BusLines,
BusPath,
ParkingSpaces,
PrestigeValue,
blVISA,
AgreementDiscount,
blSingle,
blOrder,
ConsumeLevel,
Commend,
Area,
NumMaxRoom,
NumMaxTable,
NumMax,
NumRoom,
NumMinRoom,
VegetablesSeries,
Signboardsvegetables,
Remark,
Status,
LoginUser,
LoginTime,
UpdateUser,
UpdateTime,
TheirTradesNo
)
values
(
61000000,
61010000,
101,
'陕西第一碗餐饮',
'SXDYWCY',
'总店',
'ZD',
NULL,
'000-00000000|-*|',
'西安市莲湖区西二环40号',
1,
61010400,
0,
NULL,
NULL,
.0,
NULL,
NULL,
getDate(),
getdate(),
NULL,
NULL,
0,
0,
0,
.0,
0,
0,
0,
NULL,
0,
0,
0,
0,
0,
0,
NULL,
NULL,
NULL,
1,
1,
getdate(),
NULL,
NULL,
1

)
select @DateType =@DateType+1
select @Count = @Count+1
-- if @DateType > 1
-- begin
-- select @DateType = 301
-- end

End

你可以看看

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧