将数据库对象脚本化到文件的存储过程? [英] Stored procedure to script database objects to file?

查看:25
本文介绍了将数据库对象脚本化到文件的存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 SQL 2005 中编写一个存储过程来将我所有的数据库对象脚本化到一个文件中.唯一的问题是......我不知道该怎么做.有人可以帮忙吗?

I'd like to write a stored procedure in SQL 2005 to script all my database objects to a file. The only problem is...I have no idea how to do it. Can anyone help?

谢谢!

推荐答案

你可以试试这样的,

首先在你的 SQL 服务器中创建一个新的存储过程,就像这样.

First of all creating a new store procedure in your SQL server, like this.

CREATE PROCEDURE ListObjectsToFile
AS
BEGIN
 select * from sysobjects;
END
GO

然后从命令行调用它,指明你的完整连接字符串和输出文件的路径/名称

And then call it from the Command Line, indicating your complete connection string and the path/name of the output file

C:\>sqlcmd -SyourServer\yourSQLServerInstance -U yourUser -P yourUserPassword -qListObjectsToFile -o C:\list.txt

C:\>sqlcmd -S yourServer\yourSQLServerInstance -U yourUser -P yourUserPassword -q ListObjectsToFile -o C:\list.txt

希望有所帮助,

桑蒂!:)

这篇关于将数据库对象脚本化到文件的存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆