MZOE'S BLOG

mzoe的个人主页

09-06
4

asp清空数据库

作者:mzoe 日期:2009-06-04 时间:16:41

  清空数据库的原理很简单,就是先删除表中的数据库,然后对其进行压缩。因为数据库压缩的主要就是释放索引,使索引空间最小化,表中的数据全部删除掉后,再压缩索引就从1开始了。具体的asp代码如下:

  1. function emptyTable() {  
  2.     var sourceDBFile = '/Include/DataBase/#fooldown#data.mdb';  
  3.     var tempDBFile = sourceDBFile.replace(/[^\/]+$/, '_temp.mdb');  
  4.     var tables = ['content''category''tag''comment''admin''adminGroup''advertisement''user''userGroup''label''link''remote']; // 需要清空的表  
  5.     tables.each(function(table) {  
  6.         table = '$'+table; // 添加表前缀  
  7.         $execute("delete from ["+table+"]"); // 清空数据  
  8.     });  
  9.     System.conn.Close();  
  10.     System.conn = null;  
  11.     var jro = Server.CreateObject("JRO.JetEngine");  
  12.     var strS = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+Server.MapPath(sourceDBFile);  
  13.     var strT = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+Server.MapPath(tempDBFile);  
  14.     jro.CompactDatabase(strS, strT);  
  15.     $del(sourceDBFile);  
  16.     System.Files.rename(tempDBFile, sourceDBFile);  
  17.     jro = null;  
  18.     print('end');  

  注:这段代码内含不少自定义的函数,直接复制不可用

更多相关 asp 数据库 的信息:

  1. 数据库置疑后重新附加失败的解决办法
  2. ASP整合UCenter

经典语录推荐:

asp清空数据库 评论 (0)

发表评论

评论只需审核一次,以后网友可以继续使用原来ID,邮箱进行回复:)