问题描述:在网站部署初期,我们会增加一部分的测试信息;当网站进行到一定程序,需要从网站老程序导数据到我们新程序中,那么此时会出现很多问题,导进来的数据量非常大,我们如何快速清空当前栏目的所有信息呢?
问题分析:基于数据量庞大的情况下,在后台手动删除信息就显得非常鸡肋和浪费时间,通过SQL直接删除数据库数据,是需要你非常清晰数据结构和表关联的;
解决方案:
一.有的人说直接删除栏目,方便快捷,然后重新创建栏目;
弊端:直接删除栏目,那么在网站模板中调用我们需要删除的栏目信息的置标需要每个都去修改,更显得无知与啰嗦;
二.分析数据结构,分析表关系,通过MYSQL运行SQL语句,达到删除栏目信息的效果
SQL语句部分:
这里提供可复制的SQL语句:
set @chan_id = int型栏目ID;
create temporary table doc_temp (
doc_id bigint
);
insert into doc_temp(doc_id) select doc_id from cms_chan_doc where chan_id = @chan_id;
delete from cms_docappendix where doc_id in(select doc_id from doc_temp);
delete from cms_dockeyword where doc_id in(select doc_id from doc_temp);
delete from cms_docrelation where doc_id in(select doc_id from doc_temp);
delete from cms_docrelation where reldoc_id in(select doc_id from doc_temp);
delete from cms_docsyn where doc_id in(select doc_id from doc_temp);
delete from cms_doctag where doc_id in(select doc_id from doc_temp);
delete from cms_document_branch where doc_id in(select doc_id from doc_temp);
delete from cms_docversion where doc_id in(select doc_id from doc_temp);
delete from cms_chan_doc where doc_id in(select doc_id from doc_temp);
delete from cms_document where id in(select doc_id from doc_temp);
drop table doc_temp;
© 2012-2024七七世界网站建设 20707.net 1125w.com 版权所有 豫ICP备14018694号-1