--以下生成整个数据库的SQL脚本
--(scptxfr.exe的路径要正确以下是我的路径)
declare @cMd varchar(1000)
set @cmd = 'master.dbo.xp_cmdshell ' +
'''c:\"Microsoft ' +
'SQL Server"' +
'\MSSQL\Upgrade\scptxfr.exe ' +
' /s YourServerName /p YourSAPassword /I /d YourDBName /f ' +
'c:\YourDBName.sql'''
exec (@cmd)工具参数说明:
SCPTXFR /s <server> /d <database> {[/I] | [/P <password>]}
{[/F <script files directory>] | [/f <single script file>]}
/q /r /O /T /A /E /C <CodePage> /N /X /H /G /Y /?
/s - Indicates the source server to connect to.
/d - Indicates the source database to script.
/I - Use integrated security.
/P - Password to use for 'sa'. Note that login ID is always 'sa'.
If /P not used or if a password does not follow the flag,
a null password is used. Not compatible with /I.
/F - The directory into which the script files should be generated.
This means one file is generated for each category of objects.
/f - The single file in which all script is to be saved.
Not compatible with /F.
/q - Use quoted identifiers in the generated scripts.
/r - Include drop statements for the objects in the script.
/O - Generate OEM script files. Cannot be used with /A or /T.
This is the default behavior.
/T - Generate UNICODE script files. Cannot be used with /A or /O.
/A - Generate ANSI script files. Cannot be used with /T or /O.
/? - Command line help.
/E - Stop scripting when error occurs.
Default behavior is to log the error, and continue.
/C - Indicate the CodePage which overrides the server CodePage.
/N - Generate ANSI PADDING.
/X - Script SPs and XPs to separate files.
/H - Generate script files without header (default: with header).
/G - Use the specified server name as the prefix for the generated
output files(to handle dashes in server name).
/Y - Generate script for Extended Properties (valid for 8.x server
only).
--(scptxfr.exe的路径要正确以下是我的路径)
declare @cMd varchar(1000)
set @cmd = 'master.dbo.xp_cmdshell ' +
'''c:\"Microsoft ' +
'SQL Server"' +
'\MSSQL\Upgrade\scptxfr.exe ' +
' /s YourServerName /p YourSAPassword /I /d YourDBName /f ' +
'c:\YourDBName.sql'''
exec (@cmd)工具参数说明:
SCPTXFR /s <server> /d <database> {[/I] | [/P <password>]}
{[/F <script files directory>] | [/f <single script file>]}
/q /r /O /T /A /E /C <CodePage> /N /X /H /G /Y /?
/s - Indicates the source server to connect to.
/d - Indicates the source database to script.
/I - Use integrated security.
/P - Password to use for 'sa'. Note that login ID is always 'sa'.
If /P not used or if a password does not follow the flag,
a null password is used. Not compatible with /I.
/F - The directory into which the script files should be generated.
This means one file is generated for each category of objects.
/f - The single file in which all script is to be saved.
Not compatible with /F.
/q - Use quoted identifiers in the generated scripts.
/r - Include drop statements for the objects in the script.
/O - Generate OEM script files. Cannot be used with /A or /T.
This is the default behavior.
/T - Generate UNICODE script files. Cannot be used with /A or /O.
/A - Generate ANSI script files. Cannot be used with /T or /O.
/? - Command line help.
/E - Stop scripting when error occurs.
Default behavior is to log the error, and continue.
/C - Indicate the CodePage which overrides the server CodePage.
/N - Generate ANSI PADDING.
/X - Script SPs and XPs to separate files.
/H - Generate script files without header (default: with header).
/G - Use the specified server name as the prefix for the generated
output files(to handle dashes in server name).
/Y - Generate script for Extended Properties (valid for 8.x server
only).
SCPTXFR /s <服务器> /d <数据库> {[/I] | [/P <密码>]}
{[/F <脚本文件目录>] | [/f <单个脚本文件>]}
/q /r /O /T /A /E /C <CodePage> /N /X /H /G /Y /?/s — 指示要连接到的源服务器。
/d — 指示要为之编写脚本的源数据库。
/I — 使用集成安全性。
/P — sa 要用的密码。请注意登录 ID 始终为 sa。
若/P不使用或标志后面没有密码,
则将使用空密码。不与 /I 兼容。
/F — 脚本文件应生成到的目录。
这意味着为每个对象分类生成一个文件。
/f — 所有脚本将保存到的单个文件。
不与 /F 兼容。
/q — 在所生成的脚本中使用被引用的标识符。
/r — 为脚本中的对象包括 drop 语句。
/O — 生成 OEM 脚本文件。无法用于 /A 或 /T。
这是默认的行为。
/T — 生成 UNICODE 脚本文件。无法用于 /A 或 /O。
/A — 生成 ANSI 脚本文件。无法用于 /T 或 /O。
/? — 命令行帮助。
/E — 发生错误时停止脚本编写。
默认行为是记录该错误而后继续。
/C — 指示替代服务器 CodePage(代码页)的 CodePage。
/N — 生成 ANSI PADDING。
/X — 编写 SP 和 XP 脚本以分隔文件。
/H — 生成不带首部的脚本文件。(默认: 带首部)。
/G — 使用指定的服务器名称作为所生成的输出文件的前缀(
中的划线)。
/Y — 为“扩展属性”生成脚本(仅对 8.x 服务器有效)。
sql200企业管理器
--右键要导出的数据库
--所有任务
--生成SQL脚本
--<常规>里选择"生成全部对象脚本"","在脚本文件中包含说明性标题"选上
--<设置格式>里,将"包含扩展属性",选上
--<选项>中,将"表脚本选项"中的内容全部选择上
--<选项>中,"安全性选项"是决定是否要包含创建数据库及用户权限等的设置,根据你的需要选择
--其他所有的选项保持默认值
--然后确定,将其保存成一个.sql文件生成数据脚本(借用第三方工具):
SQL Server 数据库SQL脚本导出器1.0
(下载地址:http://www.csdn.net/cnshare/soft/19/19892.shtm)
(1) 支持所有数据类型(如binary,text,image)
(2) 支持表结构、索引、所有记录到SQL脚本
(3) 支持数据库、表的浏览
(4) SQL语句的编辑、执行
(5) 可备份数据库、表结构、记录