CMD敕令操作MSSQL2005數據庫(敕令整頓)。本站提示廣大學習愛好者:(CMD敕令操作MSSQL2005數據庫(敕令整頓))文章只能為提供參考,不一定能成為您想要的結果。以下是CMD敕令操作MSSQL2005數據庫(敕令整頓)正文
翻開CMD敕令
履行:sqlcmd/?
這是sqlcmd敕令的一些贊助信息
經由過程下面可以曉得怎樣連數據庫了
履行:sqlcmd -S 辦事器地址 -d 數據庫稱號 -U 用戶暗碼 -P 暗碼
以下是操作數據庫的一下敕令
0. 創立數據庫
CREATE DATABASE DB001
1. 創立用戶
CREATE LOGIN USER1
WITH PASSWORD = 'USER_PW';
2. 修正數據的一切者
USE DB001
exec sp_changedbowner 'USER1'
GO
3. 設置READ_COMMITTED_SNAPSHOT
ALTER DATABASE [DB001] SET READ_COMMITTED_SNAPSHOT ON
GO
4.修正字符集
ALTER DATABASE DB001 COLLATE SQL_Latin1_General_CP437_CS_AS
GO
5. 獲得一切數據庫名:
Select Name FROM Master..SysDatabases
6 . 獲得一切表名:
select name from sysobjects where type='U'
XType='U':表現一切用戶表;
XType='S':表現一切體系表;
7. 獲得一切字段名:
Select Name from SysColumns Where id=Object_Id('TableName')
8. 檢查與某一個表相干的視圖、存儲進程、函數
select a.* from sysobjects a, syscomments b where a.id = b.id and b.text like '%TableName%'
9. 查詢某一個表的字段和數據類型
select column_name,data_type from information_schema.columns
where table_name = N'TableName'
10. 獲得數據庫文件途徑
select ltrim(rtrim(filename)) from dbname ..sysfiles where charindex('MDF',filename)>0
or
select ltrim(rtrim(filename)) from dbname ..sysfiles where charindex('LDF',filename)>0
MSSQL2005_數據庫備份語句
--完全備份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Full_20070908.bak'
--差別備份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Diff_20070908.bak'
With Differential
--日記備份,默許截斷日記
Backup Log NorthwindCS
To disk='G:\Backup\NorthwindCS_Log_20070908.bak'
--日記備份,不截斷日記
Backup Log NorthwindCS
To disk='G:\Backup\NorthwindCS_Log_20070908.bak'
With No_Truncate
--截斷日記不保存
Backup Log NorthwindCS
With No_Log
--或許
Backup Log NorthwindCS
With Truncate_Only
--截斷以後日記文件不會變小
--有需要可以停止壓縮
--文件備份
Exec Sp_Helpdb NorthwindCS --檢查數據文件
Backup Database NorthwindCS
File='NorthwindCS' --數據文件的邏輯名
To disk='G:\Backup\NorthwindCS_File_20070908.bak'
--文件組備份
Exec Sp_Helpdb NorthwindCS --檢查數據文件
Backup Database NorthwindCS
FileGroup='Primary' --數據文件的邏輯名
To disk='G:\Backup\NorthwindCS_FileGroup_20070908.bak'
With init
--朋分備份到多個目的
--恢復的時刻不許可喪失任何一個目的
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Full_1.bak'
,disk='G:\Backup\NorthwindCS_Full_2.bak'
--鏡像備份
--每一個目的都是雷同的
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Mirror_1.bak'
Mirror
To disk='G:\Backup\NorthwindCS_Mirror_2.bak'
With Format --第一次做鏡像備份的時刻格局化目的
--鏡像備份到當地和長途
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Mirror_1.bak'
Mirror
To disk='\\192.168.1.200\Backup\NorthwindCS_Mirror_2.bak'
With Format
--天天生成一個備份文件
Declare @Path Nvarchar(2000)
Set @Path ='G:\Backup\NorthwindCS_Full_'
+Convert(Nvarchar,Getdate(),112)+'.bak'
Backup Database NorthwindCS
To disk=@Path
--從NoRecovery或許
--Standby形式恢單數據庫為可用
Restore Database NorthwindCS_Bak
With Recovery
--檢查目的備份中的備份集
Restore HeaderOnly
From Disk ='G:\Backup\NorthwindCS_Full_20070908.bak'
--檢查目的備份的第一個備份集的信息
Restore FileListOnly
From Disk ='G:\Backup\NorthwindCS_Full_20070908_2.bak'
With File=1
--檢查目的備份的卷標
Restore LabelOnly
From Disk ='G:\Backup\NorthwindCS_Full_20070908_2.bak'
--備份設置暗碼掩護備份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Full_20070908.bak'
With Password = '123',init
Restore Database NorthwindCS
From disk='G:\Backup\NorthwindCS_Full_20070908.bak'
With Password = '123'