我有个CLASS表如果我把CLASS表中某个项删除那么 就要将 ARTICLE文章表中 父类 或 子类 中的 文章移动到 
RecycleBinArticle 这个表中- -~
可是本人才疏学浅 无法实现
所以期待各位大大能解决掉..
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[ClassDel]
@id int
as
begin
--返回这个类下的所有子类 一遍程序再次调用删除
select subclass from class where id=@id
-- 向垃圾回收站增加类别已经被消除的文章
insert into RecycleBinArticle (ArticleId,Title,FileName)
values ()
-- 删除 类
delete class where id=@id
-- 删除 和这个类有关的文章
delete article where parentclass=@id or subclass=@id
end这个是我写的...

解决方案 »

  1.   

    insert后面没跟东西?你写点数据来,这个很好实现
      

  2.   

    我就是不知道
    MSSQL里面怎么循环读数据啊
    - -~
    伤到了...所以我 INSERT INTO 就没有写任何东西啊
      

  3.   

    ALTER proc [dbo].[ClassDel]
    @id int
    as
    begin
        --返回这个类下的所有子类 一遍程序再次调用删除
         declare @t table(ID int,PID int,Level INT)    
        declare @i int
        set @i = 1
        insert into @t select subclass,parentclass,@i from class where ID = @ID    
        while @@rowcount<>0
        begin
            set @i = @i + 1        
            insert into @t 
            select 
                a.subclass,a.parentclass,@i 
            from 
                class a,@t b 
            where 
                a.parentclass=b.subclass and b.Level = @i-1
        end
       
        -- 向垃圾回收站增加类别已经被消除的文章
        insert into RecycleBinArticle (ArticleId,Title,FileName)
        select ArticleId,Title,FileName 
        from article 
        where subclass in (select subclass from @t)
        -- 删除 类
        delete class where id=@id
        -- 删除 和这个类有关的文章
        delete article where subclass in (select subclass from @t)endgo