select 'drop table '+name from sysobjects where name like '#%';
output to c:\droptmp.sql format fixed
go
read c:\droptmp.sql
go
commit
解决方法:
如果能够用ISQL连上数据库的话,我们还可以用以下的步骤尝试尽量恢复数据库。
一、第一要做的是备份数据库,以防在操作中对数据库造成更大的损坏;
二、利用ISQL的ISQL/DATABASE TOOLS中的REBUILD DATABASE功能,对数据库重建一下,重建过程中如果出现“非法操作”就把当时处理的表先手工倒出,再删除,等到重建完成之后再手工把该表倒入。手工倒入倒出的操作如下:
(以LSJSJH为例,其中D:\TEMP为已存在的路径)
/*转出表*/
select * from lsjsjh;
output to D:\TEMP\lsjsjh.dbf format foxpro
/*删除表*/
drop table lsjsjh
/*转入表*/
input into lsjsjh from d:\temp\lsjsjh.dbf format foxpro
三、如果REBUILD功能失败(如某些表根本无法删除,导致重建中断),我们可以试用下面的方法,对有用数据进行转出,再到一个新的空帐套中去转入。(请注意下面的SQL语句中D:\TEMP作为临时路径必须是已经存在的)
1、形成修复数据库的转出文件,执行:
select 'select * from '+name+';output to D:\TEMP\'+name
+'.dbf format foxpro'+char(13)+char(10)+'go'
from sysobjects where type='u' and substring(name,1,1)!='#';
output to d:\temp\out.sql format fixed
然后,再执行read d:\temp\out.sql
2、形成修复数据库的转入文件,执行:
select 'delete '+name+char(13)+char(10)+'go'+char(13)+char(10)
+'input into '+name+' from D:\TEMP\'+name+'.dbf format foxpro'
+char(13)+char(10)+'go'
from sysobjects where type='u' and substring(name,1,1)!='#';
output to d:\temp\in.sql format fixed