I have this table:CREATE TABLE Workspaces (AreaNr CHAR(2) CONSTRAINT ck_a_areanr REFERENCES Areas(AreaNr) ON DELETE CASCADE ON UPDATE NO ACTION,SpaceNr INT CONSTRAINT ck_spacenr CHECK (SpaceNr > 0 AND SpaceNr < 1001),Area DECIMAL(2,1) CONSTRAINT ck_areal CHECK (area > 0),CONSTRAINT ck_workspaces PRIMARY KEY (AreaNr, SpaceNr))
Now I want to create a trigger that prevents a delete on a single row (randomly chosen) from the table Workspaces. At the moment I have the following trigger, but this trigger still allows removal of single rows.Current trigger:CREATE TRIGGER deleteWorkspace ON WorkspacesFOR DELETE ASBEGINDECLARE @Count intSET @Count = @@ROWCOUNT;IF @Count >= (SELECT SUM(row_count)FROM sys.dm_db_partition_statsWHERE OBJECT_ID = OBJECT_ID('Workspaces') AND index_id = 1)BEGINRAISERROR('You cannot delete all rows from Workspaces!',16,1)ROLLBACK TRANSACTIONRETURN;ENDENDGO
Desired result: I want to be able to prevent a delete on a single row on the table above, and I would be very thankful if someone could help me to alter the trigger above so that this could be fixed. Does anyone know how this can be done?