简体   繁体   English

插入后创建sql触发器

[英]create sql trigger after insert

i have two tables first table orders_details with columns orders_id ,date, admin_id, comments我有两个表,第一个表 orders_details 与列 orders_id ,date,admin_id,comments

second table orders_tracking with columns orders_id ,date, admin_id第二个表 orders_tracking 与列 orders_id ,date, admin_id

in orders_details i have duplicates of rows在 orders_details 我有重复的行

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我想创建触发器,在行插入到 orders_details 之后,c 触发器检查 order_id 和 admin_id 是否已经存在,orders_tracking 中的日期列更新(从 orders_details 获取日期)否则插入

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现在插入orders_details有新的插入

 order_id admin_id date(timestamp) comments
  5         2          111199111     test

update now in orders_details have new insert现在在 orders_details更新有新的插入

 order_id admin_id date(timestamp) comments
  1         2          111199111     test

then orders_tracking然后orders_tracking

id order_id admin_id date(timestamp) 
1  1         2          111199111     
2  1         3          111111161 
3  5         2          111199111

step-1 : create a table orders_details步骤 1:创建一个表 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需要更多细节访问: 插入后的sql触发器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM