how to write Trigger
- hi ,
I want to write a Trigger while user credentials are checking.
I want to insert his id and datetime when he logged in and also his status.
I had a table tblUsers which ontains list of users.
how can I write Trigger when user atempt for login?
please help me I am new to triggers.
Thanks in advance- Moved byChunSong Feng -MSFTMSFTThursday, November 05, 2009 6:44 AMmore appropriate in t-sql forum (From:Getting started with SQL Server)
Answers
Why do u want to stick only to trigger...
You can write a Stored procedure and execute it when the user logins..
CREATE PROCEDURE AddCredentilas @sessionID INT
AS
SET NOCOUNT ON;DECLARE @data1 Datetime
DECLARE @data2 INT
DECLARE @data3 INT
DECLARE @maxcl INTSET @data1=getdate();
SET @data2=userID:
INSERT INTO tblUsers
values(@data1,@data2,...)
ENDGO
you can execute it code behind
if(user is authenticate)
exec AddCredentilas session_value
something like that..- Marked As Answer bySQLUSAAnswererSaturday, November 07, 2009 9:33 AM
- Proposed As Answer byAnuj Sadani Tuesday, November 03, 2009 1:40 PM
All Replies
- hi,
Check this link
http://doc.ddart.net/mssql/sql70/create_8.htm
Rajesh Jonnalagadda http://www.ggktech.com - hi Rajesh,
Thanks For your quick Reply.
I want to write trigger to insert some records when we are checking tblCustomers for their credentilas.
CREATE TRIGGER trigger_name
ON table
[WITH ENCRYPTION]
{
{FOR { [DELETE] [,] [INSERT] [,] [UPDATE] }
[WITH APPEND]
[NOT FOR REPLICATION]
AS
sql_statement [...n]
}
|
{FOR { [INSERT] [,] [UPDATE] }
[WITH APPEND]
[NOT FOR REPLICATION]
AS
{ IF UPDATE (column)
[{AND | OR} UPDATE (column)]
[...n]
| IF (COLUMNS_UPDATED() {bitwise_operator} updated_bitmask)
{ comparison_operator} column_bitmask [...n]
}
sql_statement [ ...n]
}
}
I am unable to understand what I had to use in place of {FOR { [DELETE] [,] [INSERT] [,] [UPDATE] }
?
please guide me. Why do u want to stick only to trigger...
You can write a Stored procedure and execute it when the user logins..
CREATE PROCEDURE AddCredentilas @sessionID INT
AS
SET NOCOUNT ON;DECLARE @data1 Datetime
DECLARE @data2 INT
DECLARE @data3 INT
DECLARE @maxcl INTSET @data1=getdate();
SET @data2=userID:
INSERT INTO tblUsers
values(@data1,@data2,...)
ENDGO
you can execute it code behind
if(user is authenticate)
exec AddCredentilas session_value
something like that..- Marked As Answer bySQLUSAAnswererSaturday, November 07, 2009 9:33 AM
- Proposed As Answer byAnuj Sadani Tuesday, November 03, 2009 1:40 PM


