易截截图软件、单文件、免安装、纯绿色、仅160KB

解决SQL Server里sp_helptext输出格式错行问题

use Master 
go 
if object_id('SP_SQL') is not null 
  drop proc SP_SQL 
go 
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 
   


相关文档:

SQL中IN,NOT IN,EXISTS,NOT EXISTS的用法和差别


SQL中IN,NOT IN,EXISTS,NOT EXISTS的用法和差别:
IN:确定给定的值是否与子查询或列表中的值相匹配。
IN 关键字使您得以选择与列表中的任意一个值匹配的行。
当要获得居住在 California、Indiana 或 Maryland 州的所有作者的姓名和州的列表时,就需要下列查询:
SELECT ProductID, ProductName from Northwind.dbo.Pro ......

SQL嵌套子查询


      使用子查询的原则
      1.一个子查询必须放在圆括号中。
      2.将子查询放在比较条件的右边以增加可读性。
      子查询不包含 ORDER BY 子句。对一个 SELECT 语句只能用一个 ORDER BY 子句,
&nb ......

sql数据导入导出

大家打开这个链接可以看到很多数据库的连接方法。http://www.connectionstrings.com
这些数据库之间的数据交换就是这个贴子所要总结的内容。
(一)SQL Server之间
把远程数据库中的数据导入到本地数据库。
http://community.csdn.net/Expert/topic/5079/5079649.xml?temp=.7512018
http://community.csdn.net/Expert/ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号