Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MS SQL Delete Trigger session variable

Author  Topic 

kok_sheng2000
Starting Member

10 Posts

Posted - 2012-05-15 : 00:20:18
Hi, Everyone.

I want to keep the log detail for my record
in MS SQL Database when user Delete a record.
So I have a SQL Trigger Delete Function in related Table.
What I want to keep is the User Name From My Software's User
who delete the record, But i have no any field keep in the table,
Is that MS SQL have any session variable or temp variable that
can let my system to update and run at once together with Trigger Delete and
so keep in the log detail table ?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-15 : 00:44:16
make use of SUSER_SNAME() function to get username

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kok_sheng2000
Starting Member

10 Posts

Posted - 2012-05-15 : 00:51:10
Hi, visakh16, Thanks For Reply .
I want the user name from my software login user name not the
MS SQL Login User name. I Means a variable user name send from my program
during Delete Operation. Tq
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-15 : 01:13:28
quote:
Originally posted by kok_sheng2000

Hi, visakh16, Thanks For Reply .
I want the user name from my software login user name not the
MS SQL Login User name. I Means a variable user name send from my program
during Delete Operation. Tq


do you've a table storing those usernames in sql server? or is it domain username?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kok_sheng2000
Starting Member

10 Posts

Posted - 2012-05-15 : 01:21:25
My Program Current Login Username, I have keep it Database,
But The problem is :-
1> There are multi-user login at a time.
2> During Trigger Delete, username that delete not send to trigger.
So, What i want to know is, how or any other way to Send / communicate
with Trigger Delete when a user delete a record. Thank in advanced ...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-15 : 22:09:18
quote:
Originally posted by kok_sheng2000

My Program Current Login Username, I have keep it Database,
But The problem is :-
1> There are multi-user login at a time.
2> During Trigger Delete, username that delete not send to trigger.
So, What i want to know is, how or any other way to Send / communicate
with Trigger Delete when a user delete a record. Thank in advanced ...


you've capture and send that information manually unless its not a domain or standard sql user

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kok_sheng2000
Starting Member

10 Posts

Posted - 2012-05-16 : 21:46:24
Oop, is like that , then no choice ... Thanks for help me ...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-16 : 21:49:42
np

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -