0

I have a table called Events that I want to insert information to.

Here is the Event table schema:

create table Evento
(
    ID int primary key identity(1,1),
    Fecha datetime not null,
    Descripcion nvarchar(256) not null,
    Aplicacion nvarchar(256) not null,
    Equipo nvarchar(256) not null,
    Usuario nvarchar(256) not null,
    Tabla nvarchar(256) not null,
    Tipo nvarchar(256) not null
)

Now here is the trigger script I'm trying to create whenever a new record is inserted into the Compra (Purchase) table:

create trigger AuditoriaCompraInsert on Compra for INSERT
as
insert into Evento select GETDATE(), CONVERT(varchar(128),i.ID), APP_NAME, 
HOST_NAME, SYSTEM_USER, 'Compra', 'Insert' from inserted i

I get these errors:

Msg 207, Level 16, State 1, Procedure AuditoriaCompraInsert, Line 3 Invalid column name 'APP_NAME'. Msg 207, Level 16, State 1, Procedure AuditoriaCompraInsert, Line 4 Invalid column name 'HOST_NAME'.

Any guidance?

1
  • I recommend that you always include a list of columns in your INSERT, like INSERT INTO Evento (col1, col2,...) SELECT.... Also, a varchar() column with values 'Insert', 'Update', etc. is less efficient than using a char(1) with a value 'I', 'U', etc. Commented Nov 19, 2010 at 13:30

1 Answer 1

3

HOST_NAME(), etc are functions. Add the parenthesis.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That was the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.