码迷,mamicode.com
首页 > 其他好文 > 详细

万能的批量删除过程

时间:2018-07-28 13:45:39      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:let   int   begin   proc   str   union all   过程   批量删除   ace   

go---创建万能批量删除
create proc [dbo].[proc_Delete]
@TableName varchar(50),
@Id varchar(5000)
as
begin
declare @strSql varchar(5000)

declare @sql varchar(4000)

set @sql=‘select col=‘‘‘+ replace(@Id,‘,‘,‘‘‘ union all select ‘‘‘)+‘‘‘‘

if OBJECT_ID(‘tempdb..#DelID‘) is not null
drop table #DelID
create table #DelID(ID VARCHAR(36))

insert into #DelID exec(@sql)

set @strSql = ‘delete from ‘+@TableName+‘ where ID in ( select ID from #DelID)‘

exec(@strSql)
end

万能的批量删除过程

标签:let   int   begin   proc   str   union all   过程   批量删除   ace   

原文地址:https://www.cnblogs.com/wslpf/p/9381356.html

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