SQL指定条件删除DEDECMS文章

已为老胡 2010-05-22 PM 1047℃ 0条

    第一点: 织梦DEDECMS的文章是分别存储在三个表里面[addonarticle],[archives],[arctiny]通过addonarticle.aid、archives.id、arctiny.id关联,删除文章时,应该删除三个表里的记录.
    第二点: 执行SQL可以从PHPMYADMIN,或者DEDECMS后台系统设置-SQL命令行工具里
    第三点: 本次手动删除内容为空或者字数少于200的文章,分了两步分别删除两个表,总结代码如下:

    1: 查看要删除文章的代码:

        select * from addonarticle where length(body)<200 
        select * from addonarticle where length(body)<200
    2: 删除内容表.

        delete from addonarticle where length(body)<200 
        delete from addonarticle where length(body)<200
    3: 查看要删除文章的第二个表的代码:

         select *   from archives t1   left join addonarticle t2 on t1.id=t2.aid   where t2.aid is null and t1.channel=1 
select * from archives t1
left join addonarticle t2 on t1.id=t2.aid
where t2.aid is null and t1.channel=1
    4: 删除第二个表.

 DELETE archives t1   from archives t1   left join addonarticle t2 on t1.id=t2.aid   where t2.aid is null and t1.channel=1 
DELETE archives t1
from archives t1
left join addonarticle t2 on t1.id=t2.aid
where t2.aid is null and t1.channel=1
    5、查看要删除文章的第三个表的代码:

 select *   from arctiny t1   left join addonarticle t2 on t1.id=t2.aid   where t2.aid is null and t1.channel=1 
select * from arctiny t1
left join addonarticle t2 on t1.id=t2.aid
where t2.aid is null and t1.channel=1
    6: 删除第三个表.

 DELETE arctiny t1   from arctiny t1   left join addonarticle t2 on t1.id=t2.aid   where t2.aid is null and t1.channel=1 
DELETE arctiny t1
from arctiny t1
left join addonarticle t2 on t1.id=t2.aid
where t2.aid is null and t1.channel=1
    如果你不查看的话,直接执行第2,4,6步就可以了,其中t1.channel=1是只操作普通文章类别的意思,防止删除软件等其他类别。

非特殊说明,本博所有文章均为博主原创。

评论啦~