RE: use of host_name( ) in triggers

From: Simon Su (yqsu@onlinemicrosoft.com)
Date: 06/03/02


From: yqsu@onlinemicrosoft.com (Simon Su (MS))
Date: Mon, 03 Jun 2002 02:04:44 GMT


Dear Ida,

I don't know what version of SQL Server you are using and what does your
code look like. I would like give you a simple example here. Please try it,
and modify the codes according to your need. Hope this helps.

create table ##temp_table (login varchar(20),computer
varchar(50),date_and_time varchar(100))

create table abc(id int)

insert into abc(id)
values(1)

insert into abc(id)
values(2)
insert into abc(id)
values(3)
insert into abc(id)
values(4)
create trigger tr_abc
on abc
for update
as
insert into ##temp_table(login,computer,date_and_time)
values(system_user,host_name(),getdate())
NOTE: The temporary table should be a global table.

Regards,
Simon Su (MS)
-----------------------------
This posting is provided Ħ°AS ISĦħ with no warranties, and confers no rights

--------------------
>Content-Class: urn:content-classes:message
>From: "Ida" <idapay@yahoo.com>
>Sender: "Ida" <idapay@yahoo.com>
>Subject: use of host_name( ) in triggers
>Date: Tue, 28 May 2002 00:40:40 -0700
>Lines: 23
>Message-ID: <7d1801c2061a$f6f2f870$a5e62ecf@tkmsftngxa07>
>MIME-Version: 1.0

>Hello! =)
>
>I need to find out who is making scrupulous changes in one
>of the database tables. What I did was to create a trigger
>for an update event for the affected table. This table
>should populate a temporary table that will record the
>login, computer name and date (using SYSTEM_USER, HOST_NAME
>() and GETDATE() ) in which the changes were made.
>
>My problem is if the host_name is used within the trigger,
>the record in the temporary table will have a NULL value
>for the host_name. However, if I run "SELECT HOST_NAME()
>from the query analyzer, the host_name is returned.
>
>Question: What must I do in order to get the desired
>result using HOST_NAME?
>
>I hope to get help from you, guys. Many thanks in advance.
>=)
>
>Kind regards,
>
>Ida
>



Relevant Pages

  • use of host_name( ) in triggers
    ... I need to find out who is making scrupulous changes in one ... of the database tables. ... for an update event for the affected table. ... My problem is if the host_name is used within the trigger, ...
    (microsoft.public.sqlserver.security)
  • Re: Activate/deactivate fields on Form
    ... With the trigger control's After Update event, ... JudyHNM wrote: ... like to open for data entry if a certain box is checked and keep them ...
    (microsoft.public.access.formscoding)
  • Re: Date Updated Column
    ... You can use code in the before update event of a form to set the values of ... MS Access MVP ... "David F" wrote in message ... > by the trigger with the INSERT date. ...
    (microsoft.public.access.gettingstarted)
  • Re: Trigger
    ... On the primary key, if it is an identity column on the original, DONT also ... Name the new table with a name that is equal to the oriignal + 'History' or ... event and the other the Update event. ... The content of the insert trigger will be ...
    (microsoft.public.sqlserver.programming)