Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.21 KB | None | 0 0
  1. ALTER TABLE Departments
  2. ALTER COLUMN ManagerId INT NULL
  3.  
  4. SELECT EmployeeID
  5. FROM Employees AS e
  6. INNER JOIN Departments AS d
  7. ON E.DepartmentID = D.DepartmentID
  8. WHERE D.Name IN ('Production', 'Production Control')
  9.  
  10. DELETE FROM EmployeesProjects
  11. WHERE EmployeeID IN
  12.         (
  13.             SELECT EmployeeID FROM Employees AS e
  14.             INNER JOIN Departments AS d
  15.             ON E.DepartmentID = D.DepartmentID
  16.             WHERE D.Name IN ('Production', 'Production Control')
  17.         )
  18.  
  19. UPDATE Employees
  20. SET ManagerID = NULL
  21. WHERE ManagerID IN
  22.         (
  23.             SELECT EmployeeID FROM Employees AS e
  24.             INNER JOIN Departments AS d
  25.             ON E.DepartmentID = D.DepartmentID
  26.             WHERE D.Name IN ('Production', 'Production Control')
  27.         )
  28.  
  29. UPDATE Departments
  30. SET ManagerID = NULL
  31. WHERE ManagerID IN
  32.         (
  33.             SELECT EmployeeID FROM Employees AS e
  34.             INNER JOIN Departments AS d
  35.             ON E.DepartmentID = D.DepartmentID
  36.             WHERE D.Name IN ('Production', 'Production Control')
  37.         )
  38.  
  39. DELETE FROM Employees
  40. WHERE EmployeeID IN
  41.         (
  42.             SELECT EmployeeID FROM Employees AS e
  43.             INNER JOIN Departments AS d
  44.             ON E.DepartmentID = D.DepartmentID
  45.             WHERE D.Name IN ('Production', 'Production Control')
  46.         )
  47.  
  48. DELETE FROM Departments
  49. WHERE Name IN ('Production', 'Production Control')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement