sql2000中三个表级联删除

create table a
(
    id int primary key,
    Content varchar(50)
)

create table b
(
    id int primary key,
    a_id int
)

create table c
(
    id int primary key,
    b_id int
)

a,b,c三个表,b表的外键是a表的主键,c表的外键是b表的主键。
删除a中数据,b和c中的相关数据也被删除,这时用触发器
--建立a表的触发器
create trigger dela on a
instead of delete
as
begin
declare @aID int
select @aID=id from deleted
delete from c where b_id in (select id from b where a_id=@aID)
delete from b where a_id=@aID
delete from a where id=@aID
end

删除b表中数据,c中的相关数据也被删除

用外键实现两个表的级联删除
--建立c表外键
alter table c add constraint fk_c_b foreign key (b_id) references b(id) on delete cascade

sql2000三个表的级联删除的更多相关文章

  1. 如何实现关系表的级联删除(ON DELETE CASCADE的用法)

    以下面两张表为例: SQL> desc person 名称                                      是否为空? 类型 --------------------- ...

  2. sql server创建外键,子母表,级联删除。

    级联删除. 最近建一个合同关系,在原有的资产平台上添加维保合同关系,维保合同问题, 需要在后面添加资产的维保合同,使用ef,该添加的冗余字段都已经添加上了,现在做这个,删除的时候只删了主表提示出问题, ...

  3. student表中创建触发器,实现student表和student _course表的级联删除

    create trigger Delete_sc on student for delete as delete student_course where student_course.s_no in ...

  4. Entity Framework Code First级联删除

    如果我们要到一对主从表增加级联删除,则要在主表中的引用属性上增加Required关键字,如: public class Destination { public int DestinationId { ...

  5. Entity Framework 级联删除

    为一对主从表增加级联删除功能 protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.E ...

  6. EF 主键自增、级联删除

    一.主键自增 1.设置数据库中,主键自增 2.设置VS中Model1.edmx

  7. gridview 级联删除、dataset

    gridview编辑列(不使用控件绑定数据源)需要如下代码:<asp:GridView ID="GridView1" runat="server" Aut ...

  8. Entity Framework Code First级联删除(转)

    使用Data Annotations: 如果我们要到一对主从表增加级联删除,则要在主表中的引用属性上增加Required关键字,如: public class Destination { public ...

  9. Django框架(十一)-- 补充:inclusion_tag、defer、only、choice、事务、创建多对多的第三张表、mvc和mtv模式

    一.inclusion_tag 1.作用 用于生成HTML片段,是数据由参数传入而变成动态 2.使用 # 1.app下新建一个模块,templatetags # 2.创建一个py文件(mytag.py ...

随机推荐

  1. void类型详解

    void含义 void的字面意思是"无类型",void*则为"无类型指针",void*可以指向任何类型的数据. void几乎只有"注释"和限 ...

  2. C#项目单步调试莫名结束问题

    今天在调试一个问题时,单步跟踪,走到某一步时突然跳出了调试,后面很多断点一个都不进来. 经过更细致的一步步调试(进入每个函数查看),定位到如下一段代码有问题: 原因是:size = 3,buff_id ...

  3. The Roadmap of my web learning.

  4. RH_KABI_RESERVE的使用

    struct mm_struct { .......... #if defined(__GENKSYMS__) || !defined(CONFIG_SPAPR_TCE_IOMMU) /* We're ...

  5. 如何查看一个class文件是否正确

    今天碰到了个问题,左思右想就是找不出问题,试验多个路径来解决问题,错误依旧. 然后我拿到了现场的包,一个很大的问题让我忽略了,这个class文件用反编译程序打不开(jd-gui.exe),非常神奇,但 ...

  6. C++学习一Virtual

    没有系统性学习C++,所以工作中使用特别别扭,也不是不会,也不是不懂,但读代码和写代码时总有点生疏感.所以该补还是补起来,现在想想还是学生时代学习的知识更加扎实,那是融入骨子里的. virtual函数 ...

  7. 微信小程序--分享报错(thirdScriptError Cannot read property 'from' of undefined;at pages/index/index page onShareAppMessage function TypeError: Cannot read property 'from' of undefined)

    分享功能: onShareAppMessage: function (res) { if (res.from === 'button') { // 来自页面内转发按钮 console.log(res. ...

  8. 接收Android数据 递归显示表格数据

    <html> <head> <title>展示</title> <script type="text/javascript" ...

  9. jquery 页面传值 汉字

    function getURLParameter(name) { return decodeURIComponent( (new RegExp('[?|&]' + name + '=' + ' ...

  10. Error:No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android

    https://www.jianshu.com/p/fd3d49c7f1f8 通过Android Studio 的Sdk Manager安装NDK,安装完之后编译失败,报错信息如下: Error:No ...