cheryl9063
asked on
SQL Trigger help
Im new to writing triggers... I need help writing a trigger on a table called Login.. If a new login is created(incrementing field called loginID is created when a new record is inserted) then a table called action is checked to see if that login exist.. If that login does not exist then it will insert a record into the table called Action with the new LoginID and action(I can get this part)
try this, you can modify it to fit your columns
CREATE TRIGGER trigLogin ON Login
FOR INSERT
AS
DECLARE @NewLoginID int
SELECT @NewLoginID = (SELECT LoginID FROM INSERTED)
insert into [action](LoginID, LoginAction)
values(@NewLoginID, 'your action')
ASKER
from another process.. That is not important.. I need help writing a trigger that inserts a new record into table Action when a table Login gets a new record
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
I'm not sure I understand you totally
<If a new login is created(incrementing field called loginID is created when a new record is inserted) then a table called action is checked to see if that login exist>
If its a new login, how can the data already exist in the action table