亚洲韩日午夜视频,欧美日韩在线精品一区二区三区,韩国超清无码一区二区三区,亚洲国产成人影院播放,久草新在线,在线看片AV色

您好,歡迎來到思海網絡,我們將竭誠為您提供優質的服務! 誠征網絡推廣 | 網站備案 | 幫助中心 | 軟件下載 | 購買流程 | 付款方式 | 聯系我們 [ 會員登錄/注冊 ]
促銷推廣
客服中心
業務咨詢
有事點擊這里…  531199185
有事點擊這里…  61352289
點擊這里給我發消息  81721488
有事點擊這里…  376585780
有事點擊這里…  872642803
有事點擊這里…  459248018
有事點擊這里…  61352288
有事點擊這里…  380791050
技術支持
有事點擊這里…  714236853
有事點擊這里…  719304487
有事點擊這里…  1208894568
有事點擊這里…  61352289
在線客服
有事點擊這里…  531199185
有事點擊這里…  61352288
有事點擊這里…  983054746
有事點擊這里…  893984210
當前位置:首頁 >> 技術文章 >> 文章瀏覽
技術文章

MS SQL server在附加多個.MDF文件時重新建立日志

添加時間:2014-2-13 17:42:36  添加: 思海網絡 
現在讓我們假設我們已經有了一個數據庫叫MyDB1,它有18個.MDF文件和17個.LDF文件。執行下面的命令。

USE [master]
  GO
  /****** Object: Database [MyDB1]  Date: 08/11/2009 11:54:20 ******/
  IF EXISTS (SELECT name FROM sys.databases WHERE name = N'MyDB1')
  DROP DATABASE [MyDB1]
  GO
  CREATE DATABASE MyDB1
  ON
  ( NAME = MyDB1_dat1,FILENAME = 'C:\Data\MyDB1.mdf'),
  ( NAME = MyDB1_dat2,FILENAME = 'C:\Data\MyDB2.mdf'),
  ( NAME = MyDB1_dat3,FILENAME = 'C:\Data\MyDB3.mdf'),
  ( NAME = MyDB1_dat4,FILENAME = 'C:\Data\MyDB4.mdf'),
  ( NAME = MyDB1_dat5,FILENAME = 'C:\Data\MyDB5.mdf'),
  ( NAME = MyDB1_dat6,FILENAME = 'C:\Data\MyDB6.mdf'),
  ( NAME = MyDB1_dat7,FILENAME = 'C:\Data\MyDB7.mdf'),
  ( NAME = MyDB1_dat8,FILENAME = 'C:\Data\MyDB8.mdf'),
  ( NAME = MyDB1_dat9,FILENAME = 'C:\Data\MyDB9.mdf'),
  ( NAME = MyDB1_dat10,FILENAME = 'C:\Data\MyDB10.mdf'),
  ( NAME = MyDB1_dat11,FILENAME = 'C:\Data\MyDB11.mdf'),
  ( NAME = MyDB1_dat12,FILENAME = 'C:\Data\MyDB12.mdf'),
  ( NAME = MyDB1_dat13,FILENAME = 'C:\Data\MyDB13.mdf'),
  ( NAME = MyDB1_dat14,FILENAME = 'C:\Data\MyDB14.mdf'),
  ( NAME = MyDB1_dat15,FILENAME = 'C:\Data\MyDB15.mdf'),
  ( NAME = MyDB1_dat16,FILENAME = 'C:\Data\MyDB16.mdf'),
  ( NAME = MyDB1_dat17,FILENAME = 'C:\Data\MyDB17.mdf'),
  ( NAME = MyDB1_dat18,FILENAME = 'C:\Data\MyDB18.mdf')
  LOG ON
  ( NAME = MyDB1_log1,FILENAME = 'C:\Data\MyDB1.ldf'),
  ( NAME = MyDB1_log2,FILENAME = 'C:\Data\MyDB2.ldf'),
  ( NAME = MyDB1_log3,FILENAME = 'C:\Data\MyDB3.ldf'),
  ( NAME = MyDB1_log4,FILENAME = 'C:\Data\MyDB4.ldf'),
  ( NAME = MyDB1_log5,FILENAME = 'C:\Data\MyDB5.ldf'),
  ( NAME = MyDB1_log6,FILENAME = 'C:\Data\MyDB6.ldf'),
  ( NAME = MyDB1_log7,FILENAME = 'C:\Data\MyDB7.ldf'),
  ( NAME = MyDB1_log8,FILENAME = 'C:\Data\MyDB8.ldf'),
  ( NAME = MyDB1_log9,FILENAME = 'C:\Data\MyDB9.ldf'),
  ( NAME = MyDB1_log10,FILENAME = 'C:\Data\MyDB10.ldf'),
  ( NAME = MyDB1_log11,FILENAME = 'C:\Data\MyDB11.ldf'),
  ( NAME = MyDB1_log12,FILENAME = 'C:\Data\MyDB12.ldf'),
  ( NAME = MyDB1_log13,FILENAME = 'C:\Data\MyDB13.ldf'),
  ( NAME = MyDB1_log14,FILENAME = 'C:\Data\MyDB14.ldf'),
  ( NAME = MyDB1_log15,FILENAME = 'C:\Data\MyDB15.ldf'),
  ( NAME = MyDB1_log16,FILENAME = 'C:\Data\MyDB16.ldf'),
  ( NAME = MyDB1_log17,FILENAME = 'C:\Data\MyDB17.ldf')
  GO

  讓我們分離這個數據庫并刪除所有的.MDF 文件。

 use master
  go
  sp_detach_db MyDB1
  go
  exec master..xp_cmdshell 'Del c:\data\mydb1.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb2.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb3.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb4.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb5.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb6.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb7.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb8.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb9.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb10.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb11.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb12.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb13.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb14.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb15.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb16.ldf'
  go
  exec master..xp_cmdshell 'Del c:\data\mydb17.ldf'
  go

  注意:我使用xp_cmdshell來刪除.ldf文件。如果你沒有激活xp_cmdshell,那么你會得到下面的錯誤。

  錯誤:

  Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1

  SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell'

  because this component is turned off as part of the security configuration for this server.

  A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more

  information about enabling 'xp_cmdshell', see "Surface Area Configuration" in SQL Server Books Online.

  你可以使用下面的事務SQL語句來激活xp_cmdshell 。

  use master

  go

  sp_configure 'show advanced options',1

  go

  reconfigure with override

  go

  sp_configure 'xp_cmdshell',1

  go

  reconfigure with override

  go

  或者,你可以在MS-DOS命令提示符中使用Windows Explorer的“Del”命令來刪除.ldf文件。

  現在,讓我們使用sp_attach_db試著只附加.MDF文件。執行下面的命令。

  sp_attach_db 'MyDB1','C:\Data\MyDB1.mdf',

  'C:\Data\MyDB2.mdf','C:\Data\MyDB3.mdf',

  'C:\Data\MyDB4.mdf','C:\Data\MyDB5.mdf',

  'C:\Data\MyDB6.mdf','C:\Data\MyDB7.mdf',

  'C:\Data\MyDB8.mdf','C:\Data\MyDB9.mdf',

  'C:\Data\MyDB10.mdf','C:\Data\MyDB11.mdf',

  'C:\Data\MyDB12.mdf','C:\Data\MyDB13.mdf',

  'C:\Data\MyDB14.mdf','C:\Data\MyDB15.mdf',

  'C:\Data\MyDB16.mdf','C:\Data\MyDB17.mdf',

  'C:\Data\MyDB18.mdf'

  結果:

  Msg 8144, Level 16, State 2, Procedure sp_attach_db, Line 0

  Procedure or function sp_attach_db has too many arguments specified.

  因為我們將附加更多的文件,所以我們不使用sp_attach_single_file_db系統存儲過程。所以讓我們使用帶有“for ATTACH_REBUILD_LOG”的“Create database”語句試著附加它們。執行下面的事務SQL語句。

 CREATE DATABASE MyDB1
  ON
  (FILENAME = 'C:\Data\MyDB1.mdf'),
  (FILENAME = 'C:\Data\MyDB2.mdf'),
  (FILENAME = 'C:\Data\MyDB3.mdf'),
  (FILENAME = 'C:\Data\MyDB4.mdf'),
  (FILENAME = 'C:\Data\MyDB5.mdf'),
  (FILENAME = 'C:\Data\MyDB6.mdf'),
  (FILENAME = 'C:\Data\MyDB7.mdf'),
  (FILENAME = 'C:\Data\MyDB8.mdf'),
  (FILENAME = 'C:\Data\MyDB9.mdf'),
  (FILENAME = 'C:\Data\MyDB10.mdf'),
  (FILENAME = 'C:\Data\MyDB11.mdf'),
  (FILENAME = 'C:\Data\MyDB12.mdf'),
  (FILENAME = 'C:\Data\MyDB13.mdf'),
  (FILENAME = 'C:\Data\MyDB14.mdf'),
  (FILENAME = 'C:\Data\MyDB15.mdf'),
  (FILENAME = 'C:\Data\MyDB16.mdf'),
  (FILENAME = 'C:\Data\MyDB17.mdf'),
  (FILENAME = 'C:\Data\MyDB18.mdf')
  for ATTACH_REBUILD_LOG
  GO
  結果:
  File activation failure. The physical file name "C:\Data\MyDB1.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB2.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB3.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB4.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB5.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB6.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB7.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB8.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB9.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB10.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB11.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB12.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB13.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB14.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB15.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB16.ldf" may be incorrect.
  File activation failure. The physical file name "C:\Data\MyDB17.ldf" may be incorrect.
  New log file 'C:\Data\MyDB1_log.LDF' was created.

  本篇文章介紹了在附加多個.MDF文件時怎樣重建日志。

關鍵字:SQL server、日志、附加

分享到:

頂部 】 【 關閉
版權所有:佛山思海電腦網絡有限公司 ©1998-2024 All Rights Reserved.
聯系電話:(0757)22630313、22633833
中華人民共和國增值電信業務經營許可證: 粵B1.B2-20030321 備案號:粵B2-20030321-1
網站公安備案編號:44060602000007 交互式欄目專項備案編號:200303DD003  
察察 工商 網安 舉報有獎  警警  手機打開網站