清空数据库的原理很简单,就是先删除表中的数据库,然后对其进行压缩。因为数据库压缩的主要就是释放索引,使索引空间最小化,表中的数据全部删除掉后,再压缩索引就从1开始了。具体的asp代码如下:
- function emptyTable() {
- var sourceDBFile = '/Include/DataBase/#fooldown#data.mdb';
- var tempDBFile = sourceDBFile.replace(/[^\/]+$/, '_temp.mdb');
- var tables = ['content', 'category', 'tag', 'comment', 'admin', 'adminGroup', 'advertisement', 'user', 'userGroup', 'label', 'link', 'remote']; // 需要清空的表
- tables.each(function(table) {
- table = '$'+table; // 添加表前缀
- $execute("delete from ["+table+"]"); // 清空数据
- });
- System.conn.Close();
- System.conn = null;
- var jro = Server.CreateObject("JRO.JetEngine");
- var strS = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+Server.MapPath(sourceDBFile);
- var strT = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+Server.MapPath(tempDBFile);
- jro.CompactDatabase(strS, strT);
- $del(sourceDBFile);
- System.Files.rename(tempDBFile, sourceDBFile);
- jro = null;
- print('end');
- }
注:这段代码内含不少自定义的函数,直接复制不可用
asp清空数据库 评论 (0)
发表评论