在开发环境中常遇到更改存储过程、函数、视图等对象,解决SQL Server2005里sp_helptext输出格式错行问题
2008-11-15 16:56
627 查看
来自:http://topic.csdn.net/u/20080804/12/f477b3d8-0017-4ef9-b516-021032be83ce.html
use Master
go
if object_id('SP_SQL') is not null
drop proc SP_SQL
go
/******************************************************************************************************************************************************
整理人:中国风(Roy)
日期:2008.01.01
******************************************************************************************************************************************************/
create proc [dbo].[SP_SQL](@ObjectName sysname)
as
set nocount on ;
declare @Print varchar(max)
if exists(select 1 from syscomments where ID=object_id(@ObjectName) and encrypted=1)
begin
Print N'對象已加密!'
return
end
if coalesce(object_id(@ObjectName,N'P'),object_id(@ObjectName,N'FN'),object_id(@ObjectName,N'IF'),object_id(@ObjectName,N'TF'),object_id(@ObjectName,N'TR'),object_id(@ObjectName,N'V')) is null
begin
Print N'對象只針對函數、存儲過程、觸發器、視圖!'
return
end
print 'Use '+db_Name()
print 'Go'
print 'if object_ID('+quotename(case when charindex(']',@ObjectName)=0 then '['+replace(rtrim(@ObjectName),'.','].[')+']' else @ObjectName end ,'''')+') is not null'
print char(9)+'Drop '+case when object_id(@ObjectName,N'P') is not null then 'Procedure ' when Coalesce(object_id(@ObjectName,N'FN'),object_id(@ObjectName,N'IF'),object_id(@ObjectName,N'TF')) is not null then 'Function ' when object_id(@ObjectName,N'TR') is not null then 'Trigger ' else 'View 'end +case when charindex(']',@ObjectName)=0 then '['+replace(rtrim(@ObjectName),'.','].[')+']' else @ObjectName end
Print 'Go'
declare @T table(Col nvarchar(max))
insert @T select object_definition(object_id(@ObjectName))+char(13)+char(10)
while (select max(Col) from @T)>''
begin
select top 1 @Print=left(Col,charindex(char(13)+char(10),Col)-1) from @T
print @Print
update @T set Col=stuff(Col,1,charindex(char(13)+char(10),Col)+1,'')
end
print 'Go'
use Master
go
if object_id('SP_SQL') is not null
drop proc SP_SQL
go
/******************************************************************************************************************************************************
整理人:中国风(Roy)
日期:2008.01.01
******************************************************************************************************************************************************/
create proc [dbo].[SP_SQL](@ObjectName sysname)
as
set nocount on ;
declare @Print varchar(max)
if exists(select 1 from syscomments where ID=object_id(@ObjectName) and encrypted=1)
begin
Print N'對象已加密!'
return
end
if coalesce(object_id(@ObjectName,N'P'),object_id(@ObjectName,N'FN'),object_id(@ObjectName,N'IF'),object_id(@ObjectName,N'TF'),object_id(@ObjectName,N'TR'),object_id(@ObjectName,N'V')) is null
begin
Print N'對象只針對函數、存儲過程、觸發器、視圖!'
return
end
print 'Use '+db_Name()
print 'Go'
print 'if object_ID('+quotename(case when charindex(']',@ObjectName)=0 then '['+replace(rtrim(@ObjectName),'.','].[')+']' else @ObjectName end ,'''')+') is not null'
print char(9)+'Drop '+case when object_id(@ObjectName,N'P') is not null then 'Procedure ' when Coalesce(object_id(@ObjectName,N'FN'),object_id(@ObjectName,N'IF'),object_id(@ObjectName,N'TF')) is not null then 'Function ' when object_id(@ObjectName,N'TR') is not null then 'Trigger ' else 'View 'end +case when charindex(']',@ObjectName)=0 then '['+replace(rtrim(@ObjectName),'.','].[')+']' else @ObjectName end
Print 'Go'
declare @T table(Col nvarchar(max))
insert @T select object_definition(object_id(@ObjectName))+char(13)+char(10)
while (select max(Col) from @T)>''
begin
select top 1 @Print=left(Col,charindex(char(13)+char(10),Col)-1) from @T
print @Print
update @T set Col=stuff(Col,1,charindex(char(13)+char(10),Col)+1,'')
end
print 'Go'
相关文章推荐
- 在开发环境中常遇到更改存储过程、函数、视图等对象,解决SQL Server2005里sp_helptext输出格式错行问题
- VS2008开发环境中容易遇到的3个问题之解决办法
- 如何部署Android开发环境以及解决部署中遇到的问题
- myeclipse配置hadoop开发环境,及遇到问题解决
- 安卓开发环境搭建及其所遇到的问题的解决
- 最近oracle开发中遇到的一些问题及解决办法(四):调试存储过程--待续
- eclipse c语言开发环境遇到的问题与解决
- windows环境下Eclipse开发MapReduce程序遇到的四个问题及解决办法
- Flex4 + FluorineFx配置开发环境时遇到的问题及解决方法
- 用vim搭建python3.x开发环境遇到的问题及解决
- VS2010无法调试问题解决 最近,因为公司开发的需要,对开发环境进行全面的升级,在这其中也遇到了不少问题,在之后将陆续整理出来,以便以后查看。 之前开发环境:VS2008,ArcGIS9.3,Ar
- CUnit开发环境搭建过程可能遇到的一些问题及解决方法
- wamp开发环境下安装Yii 可能会遇到的问题及解决方法
- Eclipse下搭建Android开发环境遇到的一些问题及解决
- 关于TP5视图分离到根目录的解决方法 原有: 为了方便前端开发,我想把视图(view)部分分离出来专门给前端进行修改 过程:在进行视图设置分离的过程遇到了问题 参考了官方文档http://www
- VS2008开发环境中容易遇到的3个问题之解决办法
- 在windows上搭建React Native开发环境时遇到licence问题的解决
- android开发环境遇到adt无法启动的问题分析及解决方法
- IDEA 开发环境中 调试Spark SQL及遇到问题解决办法
- myeclipse配置hadoop开发环境,及遇到问题解决