Jump to content

trigger sql server


filipelou
 Share

Recommended Posts

Olá.Eu tenho este trigger para verificar se o campo tipo é preenchido com Normal ou Administrador no sql server

CREATE TRIGGER tr_Utilizador_I on Utilizador FOR INSERT AS

    IF tipo<>"Administrador" OR tipo<>"Normal"

    BEGIN

        RAISERROR ('Tipo de Utilizador Incorrecto', 16, 1)

        ROLLBACK TRAN

        RETURN

    END

GO

mas dá-me os seguintes erros:

Msg 207, Level 16, State 1, Procedure tr_Utilizador_I, Line 2

Invalid column name 'tipo'.

Msg 207, Level 16, State 1, Procedure tr_Utilizador_I, Line 2

Invalid column name 'Administrador'.

Link to comment
Share on other sites

mas experimenta isto a ver o que dá

CREATE TRIGGER tr_Utilizador_I on Utilizador 
AFTER INSERT
AS
DECLARE @tipo CHAR(20)
SELECT @tipo = NomeDoCampo FROM INSERTED

    IF (@tipo<>'Administrador' OR tipo<>'Normal')
    BEGIN
        RAISERROR ('Tipo de Utilizador Incorrecto', 16, 1)
        ROLLBACK TRAN
        RETURN
    END
GO
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.