Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE usp_DeleteEmployeesFromDepartment (@departmentId INT)
- AS
- ALTER TABLE [EmployeesProjects] NOCHECK CONSTRAINT ALL -- disable all constraints in the tables
- ALTER TABLE [Employees] NOCHECK CONSTRAINT ALL
- ALTER TABLE [Projects] NOCHECK CONSTRAINT ALL
- ALTER TABLE [Departments] NOCHECK CONSTRAINT ALL
- ALTER TABLE [Addresses] NOCHECK CONSTRAINT ALL
- ALTER TABLE [Towns] NOCHECK CONSTRAINT ALL
- DELETE FROM [dbo].[Employees]
- WHERE [dbo].[Employees].DepartmentID = @departmentId;
- DELETE FROM [dbo].[Departments]
- WHERE [dbo].[Departments].DepartmentID = @departmentId;
- ALTER TABLE [EmployeesProjects] CHECK CONSTRAINT ALL -- re-create all constraints in the tables
- ALTER TABLE [Employees] CHECK CONSTRAINT ALL
- ALTER TABLE [Projects] CHECK CONSTRAINT ALL
- ALTER TABLE [Departments] CHECK CONSTRAINT ALL
- ALTER TABLE [Addresses] CHECK CONSTRAINT ALL
- ALTER TABLE [Towns] CHECK CONSTRAINT ALL
- SELECT COUNT(EmployeeID)
- FROM Employees
- WHERE DepartmentID = @departmentId;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement