Link to home
Start Free TrialLog in
Avatar of cheryl9063
cheryl9063Flag for United States of America

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)
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image


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

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')

Open in new window

Avatar of cheryl9063

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
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!