Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
I have a site that has been created using the asp.net membership schema. I want to set up a trigger on the aspnet_users table that inserted the user_id and the user_name of the new row into another table.

How can I get the values from the last insert?

I can select by the last date_created but that looks smelly.

Is there any better way?

1 Answer

0 votes
by (12.7k points)
edited by

Try the following code for the SQL Server Trigger:

CREATE TRIGGER yourNewTrigger ON yourSourcetable
FOR INSERT
AS

INSERT INTO yourDestinationTable
        (col1, col2    , col3, user_id, user_name)
    SELECT
        'a'  , default , null, user_id, user_name
        FROM inserted

go

 Want to learn more concepts related to SQL? Join SQL Certification by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...