shashankj
shashankj

Reputation: 37

How can I write a trigger that can copy new row from a table on insertion to another table?

I have two tables, creds and users.

users

email password fullName contact city

creds

email password

I need a trigger which can copy email and password from users into creds upon insertion of new rows.

Upvotes: 2

Views: 117

Answers (1)

Abhishek Pandit
Abhishek Pandit

Reputation: 28

Hope this following trigger works for you. More or less it will be like this

CREATE TRIGGER user_trigger
ON creds 
FOR INSERT
AS  
BEGIN 
    Insert into users(email, password, fullname, contact, city) 
    select distinct u.email, u.password
    from inserteduser u
    left join creds c
    on u.email = c.email and u.password = c.password
END;

Upvotes: 1

Related Questions