filipelou Posted June 6, 2008 at 02:22 PM Report Share #189780 Posted June 6, 2008 at 02:22 PM 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 More sharing options...
vitortomaz Posted June 6, 2008 at 06:21 PM Report Share #189823 Posted June 6, 2008 at 06:21 PM queres mesmo que o campo seja preenchido com esse texto? ou queres ter uma tabela com tipos de utilizadores e na tabela de utilizadores teres uma chave estrangeira para a tabela de tipos de utilizador? 😛 andar a repetir "strings" não é muito bom 😉 http://vitortomaz.blogspot.com/ Link to comment Share on other sites More sharing options...
vitortomaz Posted June 6, 2008 at 06:30 PM Report Share #189827 Posted June 6, 2008 at 06:30 PM 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 http://vitortomaz.blogspot.com/ Link to comment Share on other sites More sharing options...
filipelou Posted June 7, 2008 at 09:21 AM Author Report Share #189927 Posted June 7, 2008 at 09:21 AM Obrigado mas fiz uma constraint assim:tipo in('Administrador','Normal') Link to comment Share on other sites More sharing options...
filipelou Posted June 9, 2008 at 07:47 AM Author Report Share #190221 Posted June 9, 2008 at 07:47 AM resolvido.Obrigado. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now