We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

SQL Trigger help

Medium Priority
305 Views
Last Modified: 2012-05-11
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)
Comment
Watch Question

Ephraim WangoyaSoftware Engineer
CERTIFIED EXPERT

Commented:

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
Ephraim WangoyaSoftware Engineer
CERTIFIED EXPERT

Commented:

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

Author

Commented:
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
Top Expert 2011
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Alpesh PatelSolution Architect at TCS (SAFe®Agilist, TOGAF® Foundation, PSM I®, MCP, MCSD)
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.