批量刪除記錄的儲存過程

2021-05-11 03:23:08 字數 893 閱讀 9593

if exists(select * from sysobjects where name='users_delete')

drop proc users_delete

gocreate proc users_delete

@id varchar(100)

asdeclare @pointprve int--開始的位置

declare @pointcurr int--當前,的位置

declare @uid int --根據刪除的id

set @pointprve=1

while(@pointprve0)

begin

set @uid=cast(substring(@id,@pointprve,@pointcurr-@pointprve)as int)--從@pointprve位置開始在@id中擷取長度為@pointcurr-@pointprve的字元,然後轉成int

delete from users where id=@uid

set @pointprve=@pointcurr+1--開始的位置等於,的位置加上1,也就是從下乙個數字開始

endelse

break

end--因為到最後乙個數的時候沒有逗號,所以@pointcurr的值小於零

set @uid=cast(substring(@id,@pointprve,len(@id)-@pointprve+1) as int)

delete from users where id=@uid

--測試儲存過程

declare @id varchar(100)

set @id='21,22,23,24,25'

exec users_delete @id

select * from users

批量刪除儲存過程的儲存過程

create procedure dropprocedure as declare cur cursor read only for select name from sysobjects where xtype p and name like drop declare name varchar 4...

批量刪除的儲存過程

批量刪除的儲存過程 根據批量刪除的sql語句可以知道 delete table where id in id1,id2,id3,寫儲存過程 create proc up del id nvarchar 20 asdelete table where id in id 此時執行會報 訊息 245,級別...

SQL SERVER 批量刪除儲存過程

sqlserver 2005一次只能刪除乙個儲存過程,如果多了,需要很長時間才能刪完,所以寫了一段語句,直接就把當然資料庫下所有使用者自定義的儲存過程給drop了。不過使用都請留心,當前開啟的資料庫哦。下面貼 declare proccur cursor forselect name from sy...