i have two tables first table orders_details with columns orders_id ,date, admin_id, comments
second table orders_tracking with columns orders_id ,date, admin_id
in orders_details i have duplicates of rows
i want to create trigger that after row insert to orders_details the c trigger check if order_id and admin_id already exist the date column update in orders_tracking (take the date from orders_details) otherwise do insert to otherwise
example orders_details
id order_id admin_id date(timestamp) comments 1 1 2 111111111 test 2 1 2 111111511 test2 3 1 2 111111711 test3 4 1 3 111111161 test4
example orders_tracking
id order_id admin_id date(timestamp) 1 1 2 111111111 2 1 3 111111161
insert now in orders_details have new insert
order_id admin_id date(timestamp) comments 5 2 111199111 test
update now in orders_details have new insert
order_id admin_id date(timestamp) comments 1 2 111199111 test
then orders_tracking
id order_id admin_id date(timestamp) 1 1 2 111199111 2 1 3 111111161 3 5 2 111199111
Advertisement
Answer
step-1 : create a table orders_details
CREATE TABLE [dbo].[orders_details]( [ID] [numeric](18, 0) NULL, [ORDER_ID] [numeric](18, 0) NULL, [ADMIN_ID] [numeric](18, 0) NULL, [DATE] [datetime] NULL, [COMMENTS] [varchar](50) NULL
) ON [PRIMARY]
Need to more details visit : sql trigger after insert