现在有2个表A和B,A中有字段ProductID,Name,Re(ProductID为主键且自动增一)
B中有字段ProductID,Name,Introduce
A中ProductID,Name 和B中的是一样的。
现在当我删除B的一列时,要把对应的A中的列同步删除掉,怎么操作?利用触发器,希望给个完全的触发器设计代码,谢谢!!在线等
B中有字段ProductID,Name,Introduce
A中ProductID,Name 和B中的是一样的。
现在当我删除B的一列时,要把对应的A中的列同步删除掉,怎么操作?利用触发器,希望给个完全的触发器设计代码,谢谢!!在线等
解决方案 »
- 关于拍拍搜索
- 请教语音聊天技术实现
- 请教ASP.NET下防止迅雷等下载软件自动分析页面下载文件的方法
- VS2003.NET的WEB项目开头里有一段代码,不清楚到底是什么作用.能否详细相告?什么时候会用到它.
- 问ASP.net的技术关键点
- IE WebControl TreeView 控件中右键菜单中数据的提交问题?
- datalist中如何实现文件上传?
- 如何将文件上传到网络路径中????
- 关于Asp文件在IE中运行效果的问题
- 如何实现这样一来的功能?
- 在asp.net中,即aspx页里面引用外部js文件后,但是却在aspx页面中访问不到外部js文件中的方法,怎么办?
- Page.IsValid else语句不好用 谢谢using System;
if object_id('[tableA]') is not null drop table [tableA]
create table [tableA] ([ProductID] int,[Name] varchar(5),[Re] varchar(50))
insert into [tableA]
select 1,'name1','r1' union all
select 2,'name2','r2' union all
select 3,'name3','r3'
--> Test Data: [tableB]
if object_id('[tableB]') is not null drop table [tableB]
create table [tableB] ([ProductID] int,[Name] varchar(5),[Introduce] varchar(50))
insert into [tableB]
select 1,'name1',null union all
select 2,'name2',null--select * from [tableA]
--select * from [tableB]
go
--Code
create trigger tr_del on tableB for delete
as
begin
delete from tableA where [ProductID]=(select [ProductID] from deleted)
and [Name]=(select [Name] from deleted)
end
go
delete from tableB where [ProductID]=1
--delete from tableB where [ProductID]=2
select * from [tableA]
select * from [tableB]
--Drop--Result
/*
(1 行受影响)
ProductID Name Re
----------- ----- --------------------------------------------------
2 name2 r2
3 name3 r3(2 行受影响)ProductID Name Introduce
----------- ----- --------------------------------------------------
2 name2 NULL
*/