delete
delete

Reputation:

Creating a simple SQL trigger

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?

Upvotes: 0

Views: 1147

Answers (1)

Donnie
Donnie

Reputation: 46903

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

Upvotes: 3

Related Questions