今天请求第三条存储过程了

lianzy 2005-07-19 03:13:08
1.表anclass
anclass_id 自动编号
2.表nclass
nclass_id自动编号
anclass_id对应anclass.anclass_id
3.表article
article_id自动编号
anclass_id对应anclass.anclass_id
nclass_id对应nclass.nclass_id
4.表comment
comment_id自动编号
article_id对应article_id

四个表的关系是从上到下
当想要删除anclass表的某一条记录时
如果只输入一个参数@anclass_id能否把属下相关表信息记录删除
...全文
52 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
phantomMan 2005-07-19
楼主得表得定义是否存在外键约束等条件,如果存在,删除得顺序应该是:
表comment-->表article-->表nclass-->表anclass
如果不存在外键,顺序无所谓
回复
jiushaoye 2005-07-19
这个做触发器多好!
回复
lcqg 2005-07-19
create proc test
@anclass_id int
as

delete from nclass where anclass_id=@anclass_id

delete from article where anclass_id=@anclass_id

delete from commnent where article_id in (select article_id from article where anclass_id=@anclass_id)

delete from nclass
where anclass_id in (select anclass_id from anclass where anclass_id=@anclass_id)

GO

或者做触发器也可

回复
jsyhello 2005-07-19
create procedure deleteAll
@anclass_id int
as
delete from commnent
where article_id in
(select article_id from article where anclass_id=@anclass_id)


delete from article
where anclass_id=@anclass_id

delete from nclass
where anclass_id in (select anclass_id from anclass where anclass_id=@anclass_id)

delete from nclass where anclass_id=@anclass_id
回复
相关推荐
发帖
应用实例
创建于2007-09-28

2.7w+

社区成员

MS-SQL Server 应用实例
申请成为版主
帖子事件
创建了帖子
2005-07-19 03:13
社区公告
暂无公告