您好,我是小DAI,专注于数据库管理员相关的技术问答,请问有什么可以帮您?

sp_help

语法


sp_help [<objname> [, terse]]

参数

<objname>

是 sysobjects 中任何对象或 systypes 中任何用户定义的数据类型或系统数据类型的名称。您不能指定数据库名称。<objname> 可以包括表、视图、预计算结果集、存储过程、日志、规则、缺省值、触发器、参照约束、加密密钥、谓词和检查约束,但在启用了 optimistic_index_lock 的情况下则表示表。如果对象所有者既不是运行该命令的用户也不是数据库所有者,则使用所有者名。

terse

以表格形式显示对象属性的简短列表。只有在对象类型为 table 时有效。

示例

示例 1

显示 sysobjects 中对象的列表并显示每一对象的名称、所有者和对象类型。还显示 systypes 中由每位用户定义的数据类型的列表,并且指出数据类型名称、存储类型、长度、空值类型、缺省名和规则名称。空值类型是 0(不允许为空值)或 1(允许为空值):


sp_help

示例 2

显示有关已分区的publishers 表的信息。sp_help 还列出分配给指定表及其索引的任何属性,并且给出该属性的类、名称、整数值、字符值和注释:


sp_help publishers

Name                  Owner              Object_Type     Create_date
--------------------- ---------------    -----------     -----------------
publishers            dbo                user table      Oct 7 2005 11:14AM
Column_name Type  Length  Prec  Scale  Nulls  Default_name  Rule_name
Access_Rule_name  Computed_Column_object    Identity
----------  ----  ------  ----- -----  -----  ------------  -----------
----------------  -----------------------    --------
pub_id     char       4    NULL    NULL     0  NULL         pub_idrule
            NULL                    NULL          0
pub_name   varchar   40    NULL    NULL      1           NULL
           NULL                    NULL          0
city       varchar   20    NULL    NULL      1           NULL
           NULL                    NULL          0
state       char      2    NULL    NULL      1           NULL
           NULL                    NULL          0

Object does not have any indexes.
keytype  object      related_objs  object_keys           related_keys
-------  ------      ------------  -----------           ---------------
primary  publishers  -- none --    pub_id,*,*,*,*,*,*,*  *,*,*,*,*,*,*,*

name        type        partition_type  partitions  partition_keys
----------  --------    --------------  ----------  --------------
publishers  base table  roundrobin               3  NULL

partition_name          partition_id   pages  segment  create_date
------------------      -------------- -----  -------  -----------------
publishers_608002166    608002166          1  default  Oct 13 2005 11:18AM
publishers_1116527980   1116527980         1  default  Oct 13 2005 11:18AM
publishers_1132528037   1132528037         1  default  Oct 13 2005 11:19AM

<h2>Partition_Conditions</h2>
NULL

Avg_pages  Max_pages  Min_pages  Ratio(Max/Avg)  Ratio(Min/Avg)
---------  ---------  ---------  --------------  --------------
        1          1          1  1.0000000       1.0000000

Lock scheme Allpages
The attribute "exp_row_size" is not applicable to tables with allpages lock scheme.

exp_row  reservepagegap  fillfactor  max_rows_per_page  identity_gap
-------  --------------  ----------  -----------------  ------------
      0               0           0                  0             0

concurrency_opt_threshold  optimistic_index_lock  dealloc_first_txtpg
-------------------------  ---------------------  -------------------
                        0                      0                    0

示例 3

显示有关已分区的 titles 表的信息:


sp_help titles 

Name                  Owner              Object_Type     Create_date
--------------------- ---------------    -----------     -----------------
titles                dbo                user table      Oct 7 2005 11:14AM
(1 row affected)
Column_name Type Length Prec Scale Nulls Default_name Rule_name    Access_Rule_name
      Identity
----------- ---- ------ ---- ----- ----- ------------ ---------    -----------------
      --------
title_id    tid       6 NULL NULL      0 NULL         title_idrule NULL
       0
title   varchar      80 NULL NULL      0 NULL         NULL         NULL
        0
type       char      12 NULL NULL      0 typedflt     NULL         NULL
        0
pub_id     char       4 NULL NULL      1 NULL         NULL         NULL
        0
price     money       8 NULL NULL      1 NULL         NULL         NULL
        0
advance   money       8 NULL NULL      1 NULL         NULL         NULL
        0
total_sales int       4 NULL NULL      1 NULL         NULL         NULL
        0
notes   varchar     200 NULL NULL      1 NULL         NULL         NULL
        0
pubdate datetime      8 NULL NULL      0 datedflt     NULL         NULL
        0
contract    bit       1 NULL NULL      0 NULL         NULL         NULL
        0
index_name      index_description                       index_keys

Object has the following indexes

index_name  index_keys      index_description  index_max_rows_per_page
index_fillfactor    index_reservepagegap  index_created      index_local
----------  ----------      -----------------  ------------------------
----------------    ---------------------  ------------      ----------
title_idx   total_sales      clustered                                 0
               0                        0  Oct 13 2005 5:20PM  Local Index

index_ptn_name        index_ptn_seg
--------------------  ---------------
p1                     default
p2                     default
p3                     default
title_idx_98505151     default

keytype   object       related_object  object_keys                     
related_keys
<h2>--------  ---------  ----------------------------------------------- </h2>
foreign   roysched     titles           title_id, *, *, *, *, *, *, * title_id, *, *, *, *, *, *, *
foreign   salesdetail  titles           title_id, *, *, *, *, *, *, * title_id, *, *, *, *, *, *
foreign   titleauthor  titles           title_id, *, *, *, *, *, *, * title_id, *, *, *, *, *, * 
foreign   titles       publishers        pub_id, *, *, *, *, *, *, * 
pub_id, *, *, *, *, *, *, *
primary   titles       -- none --        title_id, *, *, *, *, *, *, *
*, *, *, *, *, *, *, * 

name    type        partition_type  partitions  partition_keys
----    ----------  --------------  ----------  --------------
titles  base table  range                    4  pubdate

partition_name  partition_id  pages  segment  create_date
--------------  ------------  -----  -------  -------------------
q1              937051343         1  default  Oct 13 2005 5:20PM
q2              953051400         1  default  Oct 13 2005 5:20PM
q3              969051457         1  default  Oct 13 2005 5:20PM
q4              985051514         1  default  Oct 13 2005 5:20PM

<h2>Partition_Conditions</h2>
VALUES <= ("3/31/2006")
VALUES <= ("6/30/2006")
VALUES <= ("9/30/2006")
VALUES <= ("12/31/2006")
VALUES <= ("3'31'2006")

Avg_pages  Max_pages  Min_pages  Ratio(Max/Avg)  Ratio(Min/Avg)
---------  ---------  ---------  --------------  --------------
        1          1          1  1.000000        1.000000

Lock scheme Allpages
The attribute 'exp_row_size" is not applicable to tables with allpages lock scheme.

exp_row  reservepagegap  fillfactor  max_rows_per_page  identity_gap
-------  --------------  ----------  -----------------  ------------
      0               0           0                  0             0

concurrency_opt_threshold  optimistic_index_lock  dealloc_first_txtpg
-------------------------  ---------------------  -------------------
                        0                       0                   0

示例 4

显示有关 titles 表信息的简短列表:


sp_help titles, terse

 Name         Owner      Object_type             Create_date
 ------------ ---------- ----------------------  --------------------------------------
 titles       dbo        user table              Oct  5 2016 10:49AM

(1 row affected)
 Column_description
 --------------------  ---------
 title_id tid          not null  
 title varchar (80)    not null 
 type char (12)        not null --Default typedflt
 pub_id char (4)       null    
 price money           null  
 advance money         null  
 total_sales int       null   
 notes varchar (200)   null   
 pubdate datetime      not null --Default datedflt 
 contract bit          not null  

 Index_description
 -------------------------------------------------------------------------------
 unique clustered index titleidind on titles ( title_id )  -- global index 
 nonclustered index titleind on titles ( title )  -- global index    

(2 rows affected)
 total_indexes global_indexes local_indexes partial_indexes
 ------------- -------------- ------------- ---------------
             2              2             0               0
 keytype        object                 related_object     object_keys                       related_keys
 -------------- ---------------------- ---------------    ------------------------------    --------------------------------
 foreign        roysched               titles             title_id, *, *, *, *, *, *, *     title_id, *, *, *, *, *, *, *
 foreign        salesdetail            titles             title_id, *, *, *, *, *, *, *     title_id, *, *, *, *, *, *, *
 foreign        titleauthor            titles             title_id, *, *, *, *, *, *, *     title_id, *, *, *, *, *, *, *
 foreign        titles                 publishers         pub_id, *, *, *, *, *, *, *       pub_id, *, *, *, *, *, *, *
 primary        titles                  -- none --        title_id, *, *, *, *, *, *, *     *, *, *, *, *, *, *, *

 Partition_details
 -----------------
 Partition type        : roundrobin
 Number of partitions  : 1
 Partition keys        : NULL

 Table_property                               Status/value
 -------------------------------------------- ----------------------------
 LOB compression level                        0
 ascinserts                                   0
 cached_index_root_page                       0
 dealloc_first_txtpg                          0
 fillfactor                                   0
 identity_gap                                 0
 lock scheme                                  allpages
 max_rows_per_page                            0
 optimistic_index_lock                        0
 reservepagegap                               0

(return status = 0)
1>

示例 5

显示有关用户“mary”所拥有的触发器 marytrig 的信息。引号不可省略,因为句点是特殊字符:


sp_help "mary.marytrig"

Name         Owner              Object_type
------------ ------------------ ----------------
marytrig     mary              trigger

Data_located_on_segment When_created
----------------------- --------------------------
not applicable          Mar 20 2002  2:03PM

示例 6

显示有关系统数据类型 money 的信息:


sp_help money

Type_name  Storage_type  Length  Prec   Scale  Nulls  Defaul_name
---------  ------------  -------  -----  -----  -----  ------------
Rule_name  Access_Rule_name  Identity
---------  ----------------  --------
money       money               8   NULL    NULL      1         NULL
NULL                   NULL          0 

示例 7

显示有关用户定义数据类型 identype 的信息。该报告指示了从其创建数据类型的基本类型、是否允许空值、绑定到该数据类型的任何规则和缺省值的名称以及是否具有 IDENTITY 属性:


sp_help identype

Type_name  Storage_type  Length  Prec   Scale  Nulls  Defaul_name
---------  ------------  -------  -----  -----  -----  ------------
Rule_name  Access_Rule_name  Identity
---------  ----------------  --------
identype        numeric        4   NULL    NULL      1         NULL
NULL                   NULL          1 

示例 8

显示一个新列,指示是否启用优化索引锁定。1 指示该选项已启用;0 指示该选项未启用:


sp_help "mytable"

</h2>
<h2>exp_row_size   reserve   pagegap   fillfactor   max_rows_per_page</h2>
           1         0         0            0                   0
<h2>concurrency_opt_threshold    optimistic_index_lock</h2>
                        0                        1

示例 9

显示一个虚拟计算列:


alter table authors add fullname as au_fname + ' ' + au_lname
sp_help authors

Object has the following computed columns

Column_Name Property
----------- --------
fullname    virtual

<h2>Text</h2>
AS au_fname + ' ' + au_lname

示例 10

将一个虚拟计算列显示为实现计算列:


alter table authors modify fullname materialzied
sp_help authors

Object has the following computed columns

Column_Name Property    
----------- ------------
fullname    materialized

<h2>Text </h2>
AS  au_fname + ' ' + au_lname
MATERIALIZED

示例 11

sp_help <table_name> 的结果集包含指示列的解密缺省名称的 Decrypt_Default_name 列。例如,可运行以下命令:


create table encr_table(col1 int encrypt decrypt_default 1)

当对 encr_table 运行 sp_help 时,它会显示以下结果:


Column_name Type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name     Computed_Column_object Identity Encrypted Decrypt_Default_name
----------- ---- ------ ---- ----- ----- --------------------- -------------- ------------------- --------- -------------------------
c1          int       4 NULL NULL      0 NULL         NULL       NULL
    NULL                          0         1 encr_table_col1_1036527695

示例 12

显示谓词对象的 Name、Owner、Object_type、Object_status 和 Create_date:


grant select on tab1 where col1 = 5 as pred1 to robert
sp_help pred1

Name  Owner  Object_type  Object_status  Create_date
----- ------ ------------- -------------- ------------
pred1 dbo    predicate     -- none --      Feb 9 2010 12:49PM

####示例 13

对于此预计算结果集:


create table numtrips (source int, destination int, count_trip int)
create precomputed result set frequent_trips unique (source, destination)
as
select * from numtrips where count_trip > 100

sp_help numtrips 返回以下内容:


Name            Owner       Object_type
Object_status
Create_date
<h2>---------------- ---------- ----------------------</h2>
-------------------------------------- 
numtrips         dbo        user table 
precomputed result set defined 
May 11 2012  6:46AM 
. . . 

sp_help frequent_trips 返回:

Name Owner

Object_type

Object_status

Create_date

---------------------------- ----------

----------------------------------------------------------------------

--------------------------------------

frequent_trips dbo

precomputed result set

immediate, enabled, enabled for QRW

May 11 2012 6:46AM

. . .



<h4>示例 14</h4>

sp_help 在 Object 状态字段中显示 execute as owner 或 execute as caller,如下所示:

create proc p1 with execute as owner asselect 1gosp_help p1Name Owner Object_type Object_statuse Create_date

---- ----- ----------- -------------- -----------

p1 dbo stored procedureexecute as ownerJun 8 2012 10:05AM

(1 row affected)Column_name Type Length Prec Scale Nulls Not_compressed Default_name

Rule _name Access_Rule_name Computed_Column_object Identity

--------------------------------------------------------------------------(return status = 0) Rule_name



<h4>示例 15</h4>

显示有关 order_number 表的减少的输出,针对内存行存储启用:

sp_help order_number, terse

Name Owner Object_type Create_date

------------ ----- ----------- -------------------

order_number dbo user table Jan 13 2016 11:14AM

(1 row affected)

Column_description

number int not null

title char (10) not null

Object does not have any indexes.

No defined keys for this object.

name type partition_type partitions partition_keys

------------ ---------- -------------- ---------- --------------

order_number base table roundrobin 1 NULL

partition_name partition_id compression_level pages row_count segment create_date

---------------- ------------ ----------------- ----- --------- ------- -------------------

ord_num_672002394 672002394 none 1 0 default Jan 13 2015 11:14AM

Partition_Conditions

NULL

Avg_pages Max_pages Min_pages Ratio(Max/Avg) Ratio(Min/Avg)

----------- ----------- ----------- --------------------------- ---------------------------

1 1 1 1.000000 1.000000

Table_property Status/value

------------------------- --------------

LOB compression level 0

cached_index_root_page 0

concurrency_opt_threshold 15

data row caching enabled

dealloc_first_txtpg 0

exp_row_size 1

fillfactor 0

identity_gap 0

keep first text page enabled

lock scheme datarows

max_rows_per_page 0

optimistic_index_lock 0

reservepagegap 0

snapshot isolation enabled



<h4>示例 16</h4>

更改表 t1 以禁用 row_caching,然后显示有关 t1 的信息:

sp_help t1

Name Owner Object_type Object_status Create_date

-------- ---------- ---------------------- ------------------------------------------------------------------------ --------------------------------------

t1 dbo user table snapshot isolation, data row caching May 25 2017 3:03AM

alter table t1 set row_caching off

go

sp_help t1

go

Name Owner Object_type Object_status Create_date

-------- ---------- ---------------------- ------------------------------------------------------------------------------------------------------------------ --------------------------------------

t1 dbo user table snapshot isolation, data row caching temporarily disabled May 25 2017 3:03AM



<h3>用法</h3>

<ul><li>对于虚拟散列表,sp_help 将报告:

使用下面的消息报告表是虚拟散列表:

Object is Virtually Hashed



使用以下语法以消息形式报告表的 hash_key_factors:

:,

:...,

=



例如:

orattribute_class attribute int_value

char_value comments

--------------------- --------------- ------------------------

-------------------------------------- -----------

hash clustered tables hash key factors NULL

id:10.0, id2:1.0, max_hash_key=1000.0 NULL

``</p> <p></li></ul><ul><li>sp_help 只查找当前数据库中的对象。</p> <p></li></ul><ul><li>如果从 tempdb 发出 sp_help,则该命令对临时表起作用。</p> <p></li></ul><ul><li>具有 IDENTITY 属性的列的“Identity”值为 1;其它列的“Identity”值为 0。在示例 2 中,没有 IDENTITY 列。</p> <p></li></ul><ul><li>sp_help 列出表上的所有索引,包括通过在 create table 或 alter table语句中定义唯一或主键约束创建的索引。该命令还列出与这些索引关联的任何属性。但 sp_help 不提供关于为表定义的完整性约束的任何信息。请使用 sp_helpconstraint 来获得有关任何完整性约束的信息。</p> <p></li></ul><ul><li>sp_help 显示以下新设置:</p> <p>a) 锁定方案,可用 create table 设置并可用 alter table 更改</p> <p>b) 所需行宽,可用 create table 设置并可用 sp_chgattribute 更改</p> <p>c) 保留页间距,可用 create table 设置并可用 sp_chgattribute 更改</p> <p>d) 行锁升级设置,可用 sp_setpglockpromote 设置或更改并可用 sp_droprowlockpromote 删除</p> <p></li></ul><ul><li>sp_help 包括来自以下来源的报告:</p> <p>a) sp_helpindex – 显示用于创建索引的键的顺序以及空间管理属性</p> <p>b) sp_helpartition – 显示表的分区信息</p> <p>c) sp_helpcomputedcolumn – 显示表的计算列信息</p> <p></li></ul><ul><li>在启用组件集成服务后,sp_help 显示有关远程对象的存储位置的信息。</p> <p></li></ul><ul><li>sp_help 可以显示加密密钥的有关信息。当密钥名称被指定为 sp_help 的参数时,该命令将列出该密钥的名称、所有者、对象类型及创建日期。</p> <p></li></ul><ul><li>对于启用了内存行存储的表,sp_help 会对行高速缓存(即使已临时禁用)和快照隔离进行报告。</p> <p></li></ul><ul><li>sp_help 指示列是否已加密,如果存在列的解密缺省名称,则还包括该名称。</p> <p></li></ul><ul><li>sp_help 显示谓词特权的相关信息。</p> <h3>查找对象的规则</h3> <p>sp_help 遵循用于查找对象的 SAP ASE 规则:</p> <p>如果您没有指定所有者名,并且拥有具有指定名称的对象,则 sp_help 将报告有关该对象的信息。</p> <p>如果您没有指定所有者名,并且不拥有具有该名称的对象,但数据库所有者拥有具有该名称的对象,则 sp_help 会报告该数据库所有者的对象的有关信息。</p> <p>如果您或数据库所有者都不拥有具有指定名称的对象,则 sp_help 会报告错误情况,即使在不同所有者的数据库中存在具有该名称的对象时也是如此。用所有者的名称限定其他数据库用户(既不是您自己也不是数据库所有者)所拥有的对象,如示例 4 中所示。</p> <p>如果您和数据库所有者都拥有具有指定名称的对象,并且您要访问数据库所有者的对象,则以 . 格式指定该名称。</p> <h3>预计算结果集和 sp_help</h3> <p>sp_help 在 Object_type 列中显示预计算结果集对象的相关信息。</p> <p>SAP ASE 服务器内部将预计算结果集对象视为用户表。如果使用预计算结果集将 sp_help 作为 ` 发出,则它将报告与列、分区、密钥、索引等相关的所有详细信息,这与针对用户表运行 sp_help 时类似。

此外,Object_Status 列将为预计算结果集返回以下信息:

  • 对于用户表 – 如果用户表中定义了任何预计算结果集对象,则返回 Object_Status 列中的 precomputed result set defined

  • 对于预计算结果集对象 – 下列情况下将返回 Object_Status 列中的以下信息:

    1 刷新模式 – immediate 或 manual

    2 预计算结果集状态 – enabled 或 disabled

    3 查询重写状态 – enable for QRW 或 disabled for QRW