@echo off
color 0A
echo ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
echo ┃ 修复置疑数据库 ┃
echo ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
echo 注意,必须先停止Pubwin EP服务,再手动启动SQL Server。
echo.
pause
cls
echo 去除置疑......
echo ==========================================================================
echo use master > updatedb_c1.sql
echo go >> updatedb_c1.sql
echo SP_CONFIGURE 'ALLOW UPDATES',1 RECONFIGURE WITH OVERRIDE >> updatedb_c1.sql
echo go >> updatedb_c1.sql
echo UPDATE SYSDATABASES SET STATUS =32768 WHERE NAME='local' >> updatedb_c1.sql
echo go >> updatedb_c1.sql
echo sp_dboption 'local', 'single user', 'true' >> updatedb_c1.sql
echo go >> updatedb_c1.sql
echo DBCC CHECKDB('local') >> updatedb_c1.sql
echo go >> updatedb_c1.sql
echo update sysdatabases set status =28 where name='local' >> updatedb_c1.sql
echo go >> updatedb_c1.sql
echo sp_configure 'allow updates', 0 reconfigure with override >> updatedb_c1.sql
echo go >> updatedb_c1.sql
echo sp_dboption 'local', 'single user', 'false' >> updatedb_c1.sql
echo go >> updatedb_c1.sql
OSQL -S localhost -E -i updatedb_c1.sql
echo ==========================================================================
del updatedb_c1.sql
echo.
pause
cls
choice /C YN /M "是否将数据内容导入空库,是或否?"
if errorlevel 2 goto Exit
if errorlevel 1 goto AttachDB
:AttachDB
set /p dbpath="附加空数据库路径,如C:\hintsoft\:"
echo ====================================================================
osql -S localhost -E -Q "EXEC sp_attach_db @dbname = 'local0', @filename1 = '%dbpath%\local_Data.MDF', @filename2 = '%dbpath%\local_log.LDF'"
echo ====================================================================
pause
:Truntables
cls
echo 清空空库中的表......
echo ====================================================================
::echo truncate table local0.dbo.hst_cashserial > updatedb_c2.sql
::echo truncate table local0.dbo.hst_dealrecord >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_discountrsvconsume >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_duty >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_duty_detail >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_event >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_messageinfo >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_paymentrequestrecord >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_usehistory >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_usepcbiz >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_workingstatusdata >> updatedb_c2.sql
::echo truncate table local0.dbo.mem_additionalinfo >> updatedb_c2.sql
::echo truncate table local0.dbo.mem_event >> updatedb_c2.sql
echo truncate table local0.dbo.mem_localdiscountaccount >> updatedb_c2.sql
echo truncate table local0.dbo.mem_localmemberbaseinfo >> updatedb_c2.sql
::echo truncate table local0.dbo.pc_layout >> updatedb_c2.sql
::echo truncate table local0.dbo.pc_layout_access >> updatedb_c2.sql
::echo truncate table local0.dbo.pc_layout_global >> updatedb_c2.sql
::echo truncate table local0.dbo.prod_category >> updatedb_c2.sql
::echo truncate table local0.dbo.prod_inputrecord >> updatedb_c2.sql
::echo truncate table local0.dbo.prod_invcheck >> updatedb_c2.sql
::echo truncate table local0.dbo.prod_invcheckdetail >> updatedb_c2.sql
::echo truncate table local0.dbo.prod_inventory >> updatedb_c2.sql
::echo truncate table local0.dbo.prod_product >> updatedb_c2.sql
::echo truncate table local0.dbo.prod_shipment >> updatedb_c2.sql
::echo truncate table local0.dbo.prod_shipmentdetail >> updatedb_c2.sql
::echo truncate table local0.dbo.prod_vendor >> updatedb_c2.sql
::echo truncate table local0.dbo.realname_card >> updatedb_c2.sql
::echo truncate table local0.dbo.sequence >> updatedb_c2.sql
::echo truncate table local0.dbo.hst_nonpayment >> updatedb_c2.sql
::echo truncate table local0.dbo.cur_userinfo >> updatedb_c2.sql
::echo truncate table local0.dbo.cfg_adminaccount >> updatedb_c2.sql
::echo truncate table local0.dbo.cfg_adminrole >> updatedb_c2.sql
::echo truncate table local0.dbo.cfg_objectresource >> updatedb_c2.sql
::echo truncate table local0.dbo.realname_frequenter >> updatedb_c2.sql
::echo truncate table local0.dbo.cfg_permissionitem >> updatedb_c2.sql
::echo truncate table local0.dbo.cfg_relativepermission >> updatedb_c2.sql
::echo truncate table local0.dbo.cfg_role >> updatedb_c2.sql
::echo truncate table local0.dbo.cfg_rolepermission >> updatedb_c2.sql
echo truncate table local0.dbo.configitem >> updatedb_c2.sql
::echo truncate table local0.dbo.cur_usehistory >> updatedb_c2.sql
::echo truncate table local0.dbo.cur_user >> updatedb_c2.sql
OSQL -S localhost -E -i updatedb_c2.sql
echo ====================================================================
del updatedb_c2.sql
echo.
pause
:ExportTables
cls
echo 导出表......
echo ====================================================================
::echo insert into local0.dbo.hst_cashserial select * from local.dbo.hst_cashserial > updatedb_c3.sql
::echo insert into local0.dbo.hst_dealrecord select * from local.dbo.hst_dealrecord >> updatedb_c3.sql
::echo insert into local0.dbo.hst_discountrsvconsume select * from local.dbo.hst_discountrsvconsume >> updatedb_c3.sql
::echo insert into local0.dbo.hst_duty select * from local.dbo.hst_duty >> updatedb_c3.sql
::echo insert into local0.dbo.hst_duty_detail select * from local.dbo.hst_duty_detail >> updatedb_c3.sql
::echo insert into local0.dbo.hst_event select * from local.dbo.hst_event >> updatedb_c3.sql
::echo insert into local0.dbo.hst_messageinfo select * from local.dbo.hst_messageinfo >> updatedb_c3.sql
::echo insert into local0.dbo.hst_paymentrequestrecord select * from local.dbo.hst_paymentrequestrecord >> updatedb_c3.sql
::echo insert into local0.dbo.hst_usehistory select * from local.dbo.hst_usehistory >> updatedb_c3.sql
::echo insert into local0.dbo.hst_usepcbiz select * from local.dbo.hst_usepcbiz >> updatedb_c3.sql
::echo insert into local0.dbo.hst_workingstatusdata select * from local.dbo.hst_workingstatusdata >> updatedb_c3.sql
::echo insert into local0.dbo.mem_additionalinfo select * from local.dbo.mem_additionalinfo >> updatedb_c3.sql
::echo insert into local0.dbo.mem_event select * from local.dbo.mem_event >> updatedb_c3.sql
echo insert into local0.dbo.mem_localdiscountaccount select * from local.dbo.mem_localdiscountaccount >> updatedb_c3.sql
echo insert into local0.dbo.mem_localmemberbaseinfo select * from local.dbo.mem_localmemberbaseinfo >> updatedb_c3.sql
::echo insert into local0.dbo.pc_layout select * from local.dbo.pc_layout >> updatedb_c3.sql
::echo insert into local0.dbo.pc_layout_access select * from local.dbo.pc_layout_access >> updatedb_c3.sql
::echo insert into local0.dbo.pc_layout_global select * from local.dbo.pc_layout_global >> updatedb_c3.sql
::echo insert into local0.dbo.prod_category select * from local.dbo.prod_category >> updatedb_c3.sql
::echo insert into local0.dbo.prod_inputrecord select * from local.dbo.prod_inputrecord >> updatedb_c3.sql
::echo insert into local0.dbo.prod_invcheck select * from local.dbo.prod_invcheck >> updatedb_c3.sql
::echo insert into local0.dbo.prod_invcheckdetail select * from local.dbo.prod_invcheckdetail >> updatedb_c3.sql
::echo insert into local0.dbo.prod_inventory select * from local.dbo.prod_inventory >> updatedb_c3.sql
::echo insert into local0.dbo.prod_product select * from local.dbo.prod_product >> updatedb_c3.sql
::echo insert into local0.dbo.prod_shipment select * from local.dbo.prod_shipment >> updatedb_c3.sql
::echo insert into local0.dbo.prod_shipmentdetail select * from local.dbo.prod_shipmentdetail >> updatedb_c3.sql
::echo insert into local0.dbo.prod_vendor select * from local.dbo.prod_vendor >> updatedb_c3.sql
::echo insert into local0.dbo.realname_card select * from local.dbo.realname_card >> updatedb_c3.sql
::echo insert into local0.dbo.sequence select * from local.dbo.sequence >> updatedb_c3.sql
::echo insert into local0.dbo.hst_nonpayment select * from local.dbo.hst_nonpayment >> updatedb_c3.sql
::echo insert into local0.dbo.cur_userinfo select * from local.dbo.cur_userinfo >> updatedb_c3.sql
::echo insert into local0.dbo.cfg_adminaccount select * from local.dbo.cfg_adminaccount >> updatedb_c3.sql
::echo insert into local0.dbo.cfg_adminrole select * from local.dbo.cfg_adminrole >> updatedb_c3.sql
::echo insert into local0.dbo.cfg_objectresource select * from local.dbo.cfg_objectresource >> updatedb_c3.sql
::echo insert into local0.dbo.realname_frequenter select * from local.dbo.realname_frequenter >> updatedb_c3.sql
::echo insert into local0.dbo.cfg_permissionitem select * from local.dbo.cfg_permissionitem >> updatedb_c3.sql
::echo insert into local0.dbo.cfg_relativepermission select * from local.dbo.cfg_relativepermission >> updatedb_c3.sql
::echo insert into local0.dbo.cfg_role select * from local.dbo.cfg_role >> updatedb_c3.sql
::echo insert into local0.dbo.cfg_rolepermission select * from local.dbo.cfg_rolepermission >> updatedb_c3.sql
echo insert into local0.dbo.configitem select * from local.dbo.configitem >> updatedb_c3.sql
::echo insert into local0.dbo.cur_usehistory select * from local.dbo.cur_usehistory >> updatedb_c3.sql
::echo insert into local0.dbo.cur_user select * from local.dbo.cur_user >> updatedb_c3.sql
OSQL -S localhost -E -i updatedb_c3.sql
echo ====================================================================
del updatedb_c3.sql
echo.
pause
cls
echo 分离数据库......
echo ====================================================================
osql -S localhost -E -Q "EXEC sp_detach_db @dbname = 'local0'"
osql -S localhost -E -Q "EXEC sp_detach_db @dbname = 'local'"
echo ====================================================================
echo.
echo 拷贝导入好的正确的数据库到相应位置。
echo.
pause
:Exit