SqlServer 循环建表删除表更新表
Posted Green.Leaf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SqlServer 循环建表删除表更新表相关的知识,希望对你有一定的参考价值。
常用于分库分表
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 循环建表删除表更新表的主要内容,如果未能解决你的问题,请参考以下文章