码迷,mamicode.com
首页 > 数据库 > 详细

SqlServer 循环建表、删除表、更新表

时间:2019-01-03 20:11:39      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:style   into   sql   begin   rom   ssi   批量删除   col   删除   

常用于分库分表

1、批量删除

declare @outter int
declare @inner int
declare @tablePrefix varchar(30)
declare @tableName varchar(36)
set @outter=1
set @inner=0
while (@outter<=12)
begin
 set @tablePrefix=BankPayOrder_+convert(varchar,@outter)+_
 while(@inner<=9)
 begin 
 set @tableName=@tablePrefix+convert(varchar,@inner)
 execute(delete from +@tableName+‘‘)
 set @inner=@inner+1
 end
 set @inner=0
 set @outter=@outter+1
end 

 

2、批量建表

declare @outter int
declare @inner int
declare @tablePrefix varchar(30)
declare @tableName varchar(36)
set @outter=1
set @inner=0
while (@outter<=12)
begin
 set @tablePrefix=BankPayOrder_+convert(varchar,@outter)+_
 while(@inner<=9)
 begin 
 set @tableName=@tablePrefix+convert(varchar,@inner)
 execute(select * into +@tableName+ from [BankPayOrderCommission_2018].[dbo].[BankPayOrder_1_0])
 set @inner=@inner+1
 end
 set @inner=0
 set @outter=@outter+1
end 

 

SqlServer 循环建表、删除表、更新表

标签:style   into   sql   begin   rom   ssi   批量删除   col   删除   

原文地址:https://www.cnblogs.com/GreenLeaves/p/10216521.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!