НАДЕЖДА ЭТО ПОМОГАЕТ.
CREATE TABLE Employee(EID INT,FirstName varchar(500),LastName varchar(50))
GO
CREATE TABLE ConstructorEmployee(EID INT,CompanyName varchar(500),SalaryPerDay bigint)
GO
CREATE TABLE Project(PID INT)
GO
CREATE TABLE ProjectsConstructorEmployees(EID int ,PID INT)
GO
INSERT INTO Employee
SELECT 1,'MANI','KANDAN'
UNION
SELECT 2,'RAM','CHARAN'
UNION
SELECT 3,'RAGU','NATH'
GO INSERT INTO ConstructorEmployee SELECT 1, 'HST', 20 UNION SELECT 2, 'RRR', 50 UNION SELECT 3, 'FRT', 90
GO
INSERT INTO PROJECT
SELECT 9
UNION
SELECT 10
UNION
SELECT 13
GO INSERT INTO ProjectsConstructorEmployees SELECT 1,9 UNION SELECT 1,10 UNION SELECT 2,13 UNION SELECT 3,9 UNION SELECT 3,10
GO
SELECT * FROM Employee
SELECT * FROM ConstructorEmployee
SELECT * FROM Project
SELECT * FROM ProjectsConstructorEmployees
GO
CREATE TRIGGER PROJ_DEL
ON Project
FOR DELETE
AS
DECLARE @A TABLE (A INT)
INSERT INTO @A
SELECT * FROM DELETED
DELETE S FROM ConstructorEmployee S WHERE EID IN(
SELECT D.EID FROM ProjectsConstructorEmployees D JOIN (
SELECT A.* FROM ProjectsConstructorEmployees A INNER JOIN @A B ON
( A.PID=B.A) INNER JOIN ConstructorEmployee C ON (A.EID = C.EID))F ON
(D.EID=F.EID)
GROUP BY D.EID
HAVING COUNT(D.EID)=1)
GO
DELETE FROM PROJECT WHERE PID=10---EID 10 MAPPED TO MORE THAN ONE PROJ SO
IT WILL NOT ALLOW FOR DELETE
DELETE FROM PROJECT WHERE PID=13---EID 13 MAPPED TO ONLY ONE PROJ SO IT
WILL ALLOW FOR DELETE