向表中插入数据的时候,自动删除重复的数据
2009-11-02 15:37
260 查看
create table EE ( ID int identity(1,1) primary key, bh int, rq datetime, sj varchar(20) ) insert into EE select 1,'2009-09-09','09:01' insert into EE select 1,'2009-09-09','09:02' create trigger tg_Del on EE for insert as --如果表中存在的话 if exists(select * from EE join inserted i on EE.bh=i.bh and EE.rq=i.rq and EE.sj=i.sj) --删除刚刚插入的信息 delete E1 from EE E1,inserted i where E1.bh=i.bh and E1.rq=i.rq and E1.sj=i.sj and i.ID>E1.ID --测试数据 insert into EE(bh,rq,sj) select 1,'2009-09-09','09:02' select * from EE ID bh rq sj ----------- ----------- ----------------------- -------------------- 1 1 2009-09-09 00:00:00.000 09:01 3 1 2009-09-09 00:00:00.000 09:02 insert into EE(bh,rq,sj) select 1,'2009-09-09','09:03' select * from EE ID bh rq sj ----------- ----------- ----------------------- -------------------- 1 1 2009-09-09 00:00:00.000 09:01 3 1 2009-09-09 00:00:00.000 09:02 4 1 2009-09-09 00:00:00.000 09:03
相关文章推荐
- 向表中插入数据的时候,自动删除重复的数据
- mysql学习总结一当数据不存在的时候插入,存在的时候进行更新,删除重复数据
- Mybatis+Oracle批量插入(自动过滤重复数据)与删除
- 重复数据删除过程中的数据自动分段
- 创建临时表,作用:插入数据,取数据,取完数据自动删除。
- 删除重复记录,保留数据库中最新插入的数据(或最早插入的数据)
- phoenix建表列名重复,导致无法删除表格且修改,插入数据。
- SQL 语句之insert语句插入数据;若表中有重复的主键或数据插入的时候要求不能报错
- 在ThinkPHP中提交表单插入数据的时候,单引号和双引号是会被自动转义的,就是会自动的加上反斜线
- 删除一个表中的重复数据同时保留第一次插入那一条以及sql优化
- mysql插入数据与删除重复记录的几个例子(收藏)
- 4000 修改CSpreadSheet commit函数,让其插入新行时不再重复删除 创建 写数据
- MySQL不插入重复数据与删除重复数据
- 在ThinkPHP中提交表单插入数据的时候,单引号和双引号是会被自动转义的
- 插入数据并删除重复
- Postgis删除空间数据报的时候,表geometry_columns相关数据自动删除
- 删除一个表中的重复数据同时保留第一次插入那一条以及sql优化
- textbox 插入的数据 做显示的时候自动换行
- MySQL不插入重复数据与删除重复数据
- 内置虚拟化,自动分层,重复数据删除,固态硬盘,IBM Storwize V7000亮点解析