sql系统中的存储过程,从中可以找到查询各种信息的语句

create procedure sys.sp_help
 @objname nvarchar(776) = NULL  -- object name we're after
as
 -- PRELIMINARY
 set nocount on
 declare @dbname sysname
  ,@no varchar(35), @yes varchar(35), @none varchar(35)
 select @no = 'no', @yes = 'yes', @none = 'none'  

 -- If no @objname given, give a little info about all objects.
 if @objname is null  ----传入空值
 begin
  -- DISPLAY ALL SYSOBJECTS --
        select
            'Name'          = o.name,
            'Owner'         = user_name(ObjectProperty( object_id, 'ownerid')),
            'Object_type'   = substring(v.name,5,31)
        from sys.all_objects o, master.dbo.spt_values v
        where o.type = substring(v.name,1,2) collate database_default and v.type = 'O9T'
        order by [Owner] asc, Object_type desc, Name asc  

  print ' '  

  -- DISPLAY ALL USER TYPES
  select
   'User_type' = name,
   'Storage_type' = type_name(system_type_id),
   'Length'  = max_length,
   'Prec'  = Convert(int,TypePropertyEx(user_type_id, 'precision')),
   'Scale'  = Convert(int,TypePropertyEx(user_type_id, 'scale')),
   'Nullable'  = case when is_nullable = 1 then @yes else @no end,
   'Default_name' = isnull(object_name(default_object_id), @none),
   'Rule_name'  = isnull(object_name(rule_object_id), @none),
   'Collation'  = collation_name
  from sys.types
  where user_type_id > 256
  order by name  

  return(0)
 end  

 -- Make sure the @objname is local to the current database.
 select @dbname = parsename(@objname,3)
 if @dbname is null
  select @dbname = db_name()
 else if @dbname <> db_name()
  begin
   raiserror(15250,-1,-1)
   return(1)
  end  

 -- @objname must be either sysobjects or systypes: first look in sysobjects
 declare @objid int
 declare @sysobj_type char(2)
 select @objid = object_id, @sysobj_type = type from sys.all_objects where object_id = object_id(@objname)  

 -- IF NOT IN SYSOBJECTS, TRY SYSTYPES --
 if @objid is null
 begin
  -- UNDONE: SHOULD CHECK FOR AND DISALLOW MULTI-PART NAME
  select @objid = type_id(@objname)  

  -- IF NOT IN SYSTYPES, GIVE UP
  if @objid is null
  begin
   raiserror(15009,-1,-1,@objname,@dbname)
   return(1)
  end  

  -- DATA TYPE HELP (prec/scale only valid for numerics)
  select
   'Type_name' = name,
   'Storage_type' = type_name(system_type_id),
   'Length'  = max_length,
   'Prec'   = Convert(int,TypePropertyEx(user_type_id, 'precision')),
   'Scale'   = Convert(int,TypePropertyEx(user_type_id, 'scale')),
   'Nullable'   = case when is_nullable=1 then @yes else @no end,
   'Default_name' = isnull(object_name(default_object_id), @none),
   'Rule_name'  = isnull(object_name(rule_object_id), @none),
   'Collation'  = collation_name
  from sys.types
  where user_type_id = @objid  

  return(0)
 end  

 -- FOUND IT IN SYSOBJECT, SO GIVE OBJECT INFO
 select
  'Name'    = o.name,
  'Owner'    = user_name(ObjectProperty( object_id, 'ownerid')),
        'Type'              = substring(v.name,5,31),
  'Created_datetime' = o.create_date
 from sys.all_objects o, master.dbo.spt_values v
 where o.object_id = @objid and o.type = substring(v.name,1,2) collate database_default and v.type = 'O9T'  

 print ' '  

 -- DISPLAY COLUMN IF TABLE / VIEW
 if exists (select * from sys.all_columns where object_id = @objid)
 begin  

  -- SET UP NUMERIC TYPES: THESE WILL HAVE NON-BLANK PREC/SCALE
  declare @numtypes nvarchar(80)
  select @numtypes = N'tinyint,smallint,decimal,int,real,money,float,numeric,smallmoney'  

  -- INFO FOR EACH COLUMN
  print ' '
  select
   'Column_name'   = name,
   'Type'     = type_name(user_type_id),
   'Computed'    = case when ColumnProperty(object_id, name, 'IsComputed') = 0 then @no else @yes end,
   'Length'     = convert(int, max_length),
   'Prec'     = case when charindex(type_name(system_type_id), @numtypes) > 0
          then convert(char(5),ColumnProperty(object_id, name, 'precision'))
          else '     ' end,
   'Scale'     = case when charindex(type_name(system_type_id), @numtypes) > 0
          then convert(char(5),OdbcScale(system_type_id,scale))
          else '     ' end,
   'Nullable'    = case when is_nullable = 0 then @no else @yes end,
   'TrimTrailingBlanks' = case ColumnProperty(object_id, name, 'UsesAnsiTrim')
          when 1 then @no
          when 0 then @yes
          else '(n/a)' end,
   'FixedLenNullInSource' = case
      when type_name(system_type_id) not in ('varbinary','varchar','binary','char')
       then '(n/a)'
      when is_nullable = 0 then @no else @yes end,
   'Collation'  = collation_name
  from sys.all_columns where object_id = @objid  

  -- IDENTITY COLUMN?
  if @sysobj_type in ('S ','U ','V ','TF') and @objid > 0
  begin
   print ' '
   declare @colname sysname
   select @colname = col_name(@objid, column_id) from sys.identity_columns where object_id = @objid
   select
    'Identity'    = isnull(@colname,'No identity column defined.'),
    'Seed'    = ident_seed(@objname),
    'Increment'   = ident_incr(@objname),
    'Not For Replication' = ColumnProperty(@objid, @colname, 'IsIDNotForRepl')
   -- ROWGUIDCOL?
   print ' '
   select @colname = null
   select @colname = name from sys.columns where object_id = @objid and is_rowguidcol = 1
   select 'RowGuidCol' = isnull(@colname,'No rowguidcol column defined.')
  end
 end  

 -- DISPLAY ANY PARAMS
 if exists (select * from sys.all_parameters where object_id = @objid)
 begin
  -- INFO ON PROC PARAMS  --查询存储过程参数--object_id=object_id(@TableName)
  print ' '
  select
   'Parameter_name' = name,
   'Type'   = type_name(user_type_id),
   'Length'   = max_length,
   'Prec'   = case when type_name(system_type_id) = 'uniqueidentifier' then precision
        else OdbcPrec(system_type_id, max_length, precision) end,
   'Scale'   = OdbcScale(system_type_id, scale),
   'Param_order'  = parameter_id,
   'Collation'   = convert(sysname, case when system_type_id in (35, 99, 167, 175, 231, 239)
      then ServerProperty('collation') end)  

  from sys.all_parameters where object_id = @objid
 end  

 -- DISPLAY TABLE INDEXES & CONSTRAINTS
 if @sysobj_type in ('S ','U ')
 begin
  print ' '
  EXEC sys.sp_objectfilegroup @objid
  print ' '
  EXEC sys.sp_helpindex @objname
  print ' '
  EXEC sys.sp_helpconstraint @objname,'nomsg'
  if (select count(*) from sysdepends where depid = @objid and deptype = 1) = 0
  begin
   raiserror(15647,-1,-1,@objname) -- No views with schemabinding reference table '%ls'.
  end
  else
  begin
            select distinct 'Table is referenced by views' = obj.name from sys.objects obj, sysdepends deps
    where obj.type ='V' and obj.object_id = deps.id and deps.depid = @objid
     and deps.deptype = 1 group by obj.name  

  end
 end
 else if @sysobj_type in ('V ') and @objid > 0
 begin
  -- VIEWS DONT HAVE CONSTRAINTS, BUT PRINT THESE MESSAGES BECAUSE 6.5 DID
  print ' '
  raiserror(15469,-1,-1,@objname) -- No constraints defined
  print ' '
  raiserror(15470,-1,-1,@objname) -- No foreign keys reference table '%ls'.
  EXEC sys.sp_helpindex @objname
 end  

 return (0) -- sp_help  

sp_help null
时间: 2024-09-29 21:18:46

sql系统中的存储过程,从中可以找到查询各种信息的语句的相关文章

在PL/SQL 开发中调试存储过程和函数的一般性方法

存储过程|函数 在PL/SQL 开发中调试存储过程和函数的一般性方法摘要: Oracle 在PLSQL中提供的强大特性使得数据库开发人员可以在数据库端完成功能足够复杂的任务, 本文将结合Oracle提供的相关程序包(package)以及一个非常优秀的第三方开发工具来介绍在PLSQL中开发及调试存储过程的方法,当然也适用于函数. 版权声明: 本文可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息.原文出处: http://www.aiview.com/notes/ora_using_

sql server中扩展存储过程随笔(几个有用的PROCEDURE小总结)

server|存储过程 在sql server中扩展存储过程直接使用的机会不是很多 我把我知道的几个有用的扩展存储过程使用方式总结如下:     --获得MS SQL的版本号 execute master..sp_msgetversion go Character_Value                              -------------------- ----------- ----------- 8.00.760             1           3  

SQL 数据库中的存储过程的参数问题

  1.SQL 数据库中的存储过程的参数问题 怎么将SQL数据库中的存储过程中的参数既作为输出变量又作为输出变量? [sql] view plaincopy --drop proc proc_test --go create proc dbo.proc_test @in int, @out int out, @in_out int output as select @out = @in + @in_out, --1 + 2 = 3 @in_out = @out + 1 --3 + 1 = 4 g

(转)关于PL/SQL Developer中对存储过程add debug information

关于PL/SQL Developer中对存储过程add debug information  http://space.itpub.net/13129975/viewspace-626245 如果使用PL/SQL Developer中选择一个存储过程debug但又debug不进去! 解决这个问题是很简单的,只需要在PL/SQL Developer中选择要debug的存储过程,然后点右键,在弹出的菜单中选择"Add debug information"后再重新开一个窗口开始debug就能

【SQL Sever】将SQL Sever中的一个数据表的数据导出为insert语句

例如:这SQL   Sever中的一张数据表,想要将这张数据表中的数据  转化成一个一个的insert语句存储在txt的文档中,那么不论走到那里这个insert语句一执行,我们就能将这个数据表中的数据插入到另一个地方了. 1>在新建查询中,创建一个对象,这个对象就是用来产生这个对象的,名字叫proc_insert,我们可以创建多个不重名的对象,当然也可以删除这个对象. 1 create proc proc_insert (@tablename varchar(256)) 2 as 3 begin

sql server中扩展存储过程大全

server|存储过程 --获得MS SQL的版本号 execute master..sp_msgetversion --得到硬盘文件信息 --参数说明:目录名,目录深度,是否显示文件 execute master..xp_dirtree 'c:' execute master..xp_dirtree 'c:',1 execute master..xp_dirtree 'c:',1,1 --列出服务器上安装的所有OLEDB提供的程序 execute master..xp_enum_oledb_p

SQL Server中利用存储过程来高性能地进行分页

分页查询的方法已经很多很多,在这里我也加入成为其中一员. SQL Server中有一个Set Rowcount的的设置,它的意思是使命令的处理在响应指定的行数之后停止处理命令,利用这个特点,我们可以借用它来在一个千万行级数据表中实现高性能分页查询.先来说说实现方式: 1.我们来假定Table中有一个已经建立了索引的主键字段ID(整数型),我们将按照这个字段来取数据进行分页. 2.页的大小我们放在@PageSize中 3.当前页号我们放在@CurrentPage中 4.如何让记录指针快速滚动到我们

[原创]一个考试系统中的存储过程用来生成试卷用的

存储过程|原创 CREATE proc paperbuild @papername char(200), @subject char(10), @xzt int,@xztn int,@tkt int,@tktn int,@pdt int,@pdtn int,@wdt int,@wdtn int as/*power by :liujunaddress:衡阳师范学院计算机系0102班选择题生成部分*/declare @bxzt int,@ken varchar(8000)declare @temps

关于SQL server中字段值为null的查询

某天有个同事问我怎么在一个表中查找某字段值为null并把它替换为另一值. 开始我觉得用 select * from 表名 where 字段=null 应该可以的.但结果是没有报错,但什么也没有显示出来. 后来又试: select * from 表名 where len(字段)=0 结果仍是什么也没有显示. 无意中,用 select * from 表名 where 字段 is null 却对了.看来好多知识是要多试才能知道的.呵呵.