备份数据库CMD命令操作MSSQL2005数据库

新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正

    打开CMD令命

    执行:sqlcmd/?

    备份数据库CMD命令操作MSSQL2005数据库_第1张图片

    这是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'

文章结束给大家分享下程序员的一些笑话语录: 3G普不普及现在已经不是看终端了,而是看应用,有好的,便宜实用的应用,花1000多买个能用的智能手机应该不是什么难事。反过来说,你200元拿一个智能手机,没有好的应用,看个电影要几十元,也是没人用3G。

你可能感兴趣的:(sql2005)