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

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能否把属下相关表信息记录删除
...全文
69 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
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

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧