高手解决下SQL Server2008不能批量导出脚本的问题

[复制链接]
查看11 | 回复5 | 2011-4-18 05:29:36 | 显示全部楼层 |阅读模式
我们项目用的的数据库是Sql Server2008的,项目用到啦大量存储过程,现在做系统迁移,每次都要导出存储过程的脚本去创建,现在数据库不能批量导出脚本,只能一个一个手动创建,很麻烦,请高手帮我解决一下数据库不能批量生成脚本的问题
回复

使用道具 举报

千问 | 2011-4-18 05:29:36 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">打开SQL2008 按F7,调出“对象资源管理器详细信息”,在左侧选中“存储过程“或”Stored Procedures“目录,到右侧窗口,全选所有的要导入的sp,在选中的sp上鼠标右键。”生成存储过程脚本为”-“Drop和Create到”-“File”,这样就可以导出所有sp,将保存后的file到产品环境下运行一下就可以了。

















<h4 class=\"ask\">追问





<pre class=\"replyask-text\" id=\"content-4304114\">高手,谢谢你,存储过程的问题可以解决啦,还有一个同样的问题我同样也创建啦大量的触发器,怎么也能同样批量导出呢,谢谢啦
回复

使用道具 举报

千问 | 2011-4-18 05:29:36 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-4305929\">同样的操作也应该可以的。
回复

使用道具 举报

千问 | 2011-4-18 05:29:36 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-4309656\">触发器里没有对象
回复

使用道具 举报

千问 | 2011-4-18 05:29:36 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-4311646\">下面这个脚本是导出备份存储过程,函数,触发器等的:
Create Proc [dbo].[Proc_ExportProc]
(
@Filter nvarchar(200) /**//*查询条件例如 where 1=1 */
)
/**//*
Create By HJ 2007-12-3
备份存储过程,函数,触发器等,可直接运行
*/
As
Begin
if @Filter is null
Set @Filter = \'\'

Declare @Text varchar(8000),
@Name nvarchar(100),
@XType nvarchar(20)
Print \'Use \' db_name()
Declare myCurrsor Cursor For

Select a.[Text],b.[name] from syscomments a
Left Outer Join Sysobjects b On a.id=b.id @Filter
Open myCurrsor
Fetch Next from myCurrsor into @Text,@Name

While @@Fetch_Status = 0 --表示读取到数据,相当于 ADO 中 Not Eof


Begin
Select @XType=xtype from Sysobjects where [name]=@Name
If @XType = \'TR\'
Begin

Print \'if Exists(Select 1 from Sysobjects where xtype=\'\'TR\'\' and [name]=\'\'\' @Name \'\'\')\'

Print \'Drop Trigger \' @Name \'\'
End
Else If @XType = \'FN\'
Begin

Print \'if Exists(Select 1 from Sysobjects where xtype=\'\'FN\'\' and [name]=\'\'\' @Name \'\'\')\'

Print \'Drop Function \' @Name \'\'
End
Else If @XType = \'P\'
Begin

Print \'if Exists(Select 1 from Sysobjects where xtype=\'\'P\'\' and [name]=\'\'\' @Name \'\'\')\'

Print \'Drop Proc \' @Name \'\'
End
Else

GoTO NextFetch
Print \'exec(\'\'\' replace(@Text,\'\'\'\',\'\'\'\'\'\') \'\'\')\'
NextFetch:

Fetch Next from myCurrsor into @Text,@Name

End
Close myCurrsor
--关闭游标

Deallocate myCurrsor--删除游标
End
回复

使用道具 举报

千问 | 2011-4-18 05:29:36 | 显示全部楼层
<pre class=\"replyask-text\" id=\"content-4644180\">我周一试试,谢谢你高手
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行