I have 2 table is USER and USER_CUSTOMER and I want to write a insert query in DAO class to create a new user but don't know how.
Anyone have a good idea or have a link to solve this problem please help
I have 2 table is USER and USER_CUSTOMER and I want to write a insert query in DAO class to create a new user but don't know how.
Anyone have a good idea or have a link to solve this problem please help
If you want to handle this at the database level, then an after insert trigger, which fires after the new record has been inserted into the USER
table, might make sense:
CREATE TRIGGER [dbo].[after_user_insert] ON [dbo].[USER] FOR INSERT
AS
BEGIN
INSERT INTO [dbo].[USER_CUSTOMER] (...)
SELECT user_id, ...
FROM INSERTED
END
You would have to fill in the missing pieces of the above insert query with your actual logic. The key point is that the INSERTED
variable is available inside the trigger, and should give you access to the user record which was just inserted. Presumably some of that information would be repeated in the new record in the USER_CUSTOMER
table.