Create a trigger that does not allow editing a record that has been referenced

0

I need help with a slogan of a job that I have been given at the university to study, and I have been trying to solve it but I can not think of how .. I am starting in SQL Server.

These are the tables of the statement :

The statement says: - Create a trigger that does not allow editing a sub-project that has already been referenced by a publication.

If you could give me the serious solution to be grateful

    
asked by Javier Siacca 03.11.2018 в 23:29
source

1 answer

0

You should do something like this:

CREATE TRIGGER [dbo].[MiTrigger]
  ON [dbo].[Subrubro]
  FOR UPDATE
  AS
    BEGIN
    SET NOCOUNT ON
    IF EXISTS(SELECT 1 FROM dbo.PublicacioneXRubro AS PXR JOIN inserted i ON PXR.IdSubrubro=i.Id)
      BEGIN
        RAISERROR('No puede editar un subrubro que tenga una publicación asociada', 16, 1)
        ROLLBACK TRANSACTION;
        SET NOCOUNT OFF
        RETURN
      END
    SET NOCOUNT OFF
    END

Good luck!

    
answered by 03.11.2018 / 23:55
source