Advertisement
hecrus

CRUD deleteItem

Oct 10th, 2020
1,232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.72 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[crud_deps_deleteItem]
  2.     @itemID int,
  3.     @username nvarchar(32)
  4. AS
  5.     -- удаление строки таблицы
  6.     SET NOCOUNT off ;
  7.    
  8.      -- проверки перед удалением
  9.      declare @count int
  10.      select @count = count(*) from hr_humans
  11.      where depID = @itemID
  12.      
  13.      if(@count>0) begin
  14.         select 'На поле есть ссылки в humans ('+cast(@count as nvarchar)+' шт.)' Msg, 0 Result
  15.         return
  16.      end  
  17.    
  18.     -- удаление элемента
  19.     delete from hr_departments where id = @itemID
  20.    
  21.     if (@@ROWCOUNT > 0) begin
  22.         select '' Msg, 1 Result
  23.     end else begin
  24.         select 'Запись не удалилась из базы' Msg, 0 Result
  25.     end
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement