易截截图软件、单文件、免安装、纯绿色、仅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调优(连接方式)

SQL调优 之 连接方式
Join是一种试图将两个表结合在一起的谓词,一次只能连接2个表,表连接也可以被称为表关联。在后面的叙述中,使用”row source”来代替”表”,因为使用row source更严谨一些,并且将参与连接的2个row source分别称为row source1和row source 2。Join过程的各个步骤经常是串行操作 ......

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 Server中使用NewID()方法产生随机集

在SQL Server中使用NewID()方法产生随机集
例如考试系统中的随机出题
刚开始想到的是Random类
但是Random效率有点低
后来想到了在数据库里的newid()
于是采用了下边方法:
select top 5 * from tablename order by newid()
在此标记一下 ......

生成表中数据的sql语法的存储过程

      一般用BCP在处理这个事情,但有时也需要一些特殊的处理,以下是生成表中的一些数据,带有where条件的选择生成数据,是我一个同事修改的,直接拿过来用了:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc proc_insert_where (@tablename varchar(256),@where varchar(256 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号