Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a insert trigger ????????????????

Status
Not open for further replies.

zeeshan13

Programmer
Jan 28, 2005
82
0
0
US
Hi all,

I have a table called Session which holds the session information of each user who logins to our internal non-web based application. As soon as the user logout the Session table removes the record for that user. So the user records is only active in to the session table as long as the user is active.
The Session table has the following fields with thier data type:

UserID(uniqueidentifier),SessionID(uniqueidentifier),Spid(int),StartTime(DateTime),Duration(DateTime),ActivitySID(uniqueidentifier),Location(varchar),LanguageID(int),UserDomain(nvarchar),UserID(nvarchar),FirstName(nvarchar),LastName(nvarchar),IsAdminuser (bit)

Now, I need to keep track of users who login anytime in to the application.
To start with, I need to create a insert trigger on Session table, that will insert a new record into a table lets say TEST , whenever there's an insert on Session table. I need to insert all fields into this TEST table for that new user.

Any help would be appreciated.

Looking for a quick response.

Thanks,
 
Assuming that the table structures are EXACTLY the same

(makes it easy for me :)

Create Trigger Session_Ins
on Session for Insert
as
Insert into Test
select * from inserted


e.g.
Code:
create table a
(c1 uniqueidentifier default newid(), c2 varchar(300))
create table b
(c1 uniqueidentifier , c2 varchar(300))
go
create trigger a_i on a for insert as insert into b select * from inserted
go
insert into a (c2) values('test')
go
select * from b


HTH

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top