svetliovd

Delete Employees and Departments 2

Oct 12th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.54 KB | None | 0 0
  1. CREATE PROC usp_DeleteEmployeesFromDepartment (@departmentId INT)
  2. AS
  3. ALTER TABLE Departments
  4. ALTER COLUMN ManagerID int NULL
  5. ALTER TABLE Employees
  6. DROP FK_Employees_Departments
  7. ALTER TABLE Employees
  8. DROP FK_Employees_Employees
  9. ALTER TABLE Departments
  10. DROP FK_Departments_Employees
  11. ALTER TABLE EmployeesProjects
  12. DROP FK_EmployeesProjects_Employees
  13. DELETE FROM Employees
  14. WHERE Employees.DepartmentID = @departmentId
  15. DELETE FROM Departments
  16. WHERE Departments.DepartmentID = @departmentId
  17.  
  18. SELECT COUNT(*) FROM Employees
  19. WHERE DepartmentID = 7
Advertisement
Add Comment
Please, Sign In to add comment