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

sp_helpconstraint

语法


sp_helpconstraint [<objname>][, detail] 

参数

<objname>

是具有 create table 或 alter table 语句定义的一个或多个完整性约束的表的名称。

detail

返回有关约束的用户的信息或错误消息。

示例

示例 1

显示 pubs3 数据库中 store_employees 表的约束信息。store_employees 表具有 stores 表的外键(stor_id)以及自身参照(mgr_id 引用 emp_id):


sp_helpconstraint store_employees

name                         defn
---------------------------  --------------------------------
store_empl_stor_i_272004000  store_employees FOREIGN KEY
                             (stor_id) REFERENCES stores(stor_id)
store_empl_mgr_id_288004057  store_employees FOREIGN KEY 
                             (mgr_id) SELF REFERENCES
                             store_employees(emp_id)
store_empl_2560039432        UNIQUE INDEX( emp_id) :
                             NONCLUSTERED, FOREIGN REFERENCE 

(3 rows affected)

Total Number of Referential Constraints: 2

Details:
-- Number of references made by this table: 2
-- Number of references to this table: 1
-- Number of self references to this table: 1

Formula for Calculation:
Total Number of Referential Constraints
= Number of references made by this table
+ Number of references made to this table
<ul><li>Number of self references within this table

示例 2

显示有关 pubs3..pubs3..salesdetail 约束的更详细信息,包括约束类型和所有约束错误消息:


sp_helpconstraint titles, detail

name                         type                    defn
        msg
------------------------     --------------          ----------------------------
        --------------------------------------------
datedflt                     default value           create default datedflt as getdate()
typedflt                     default value           create default typedflt as "UNDECIDED"
titles_pub_id_96003373       referential constraint  titles FOREIGN KEY (pub_id) 
                                                     REFERENCES publishers(pub_id)
        standard system error message number : 547
roysched_title__144003544    referential constraint  roysched FOREIGN KEY (title_id) 
                                                     REFERENCES titles(title_id)
        standard system error message number : 547
salesdetai_title__368004342  referential constraint  salesdetail FOREIGN KEY (title_id) 
                                                     REFERENCES titles(title_id)
        standard system error message number : 547
titleautho_title__432004570  referential constraint  titleauthor FOREIGN KEY (title_id) 
                                                     REFERENCES titles(title_id)
        standard system error message number : 547
titles_800033162                unique constraint    UNIQUE INDEX ( title_id) : 
                                                     NONCLUSTERED, FOREIGN REFERENCE
        standard system error message number : 2601

(7 rows affected)

Total Number of Referential Constraints: 4

Details:
-- Number of references made by this table: 1
-- Number of references to this table: 3
-- Number of self references to this table: 0

Formula for Calculation:
Total Number of Referential Constraints
= Number of references made by this table
+ Number of references made to this table
</li></ul><ul><li>Number of self references within this table.

示例 3

显示 pubs3 数据库中所有表的列表:


sp_helpconstraint

id          name              Num_referential_constraints
----------- ----------------- ---------------------------
   80003316 titles                                      4
   16003088 authors                                     3
  176003658 stores                                      3
  256003943 salesdetail                                 3
  208003772 sales                                       2
  336004228 titleauthor                                 2
  896006223 store_employees                             2
   48003202 publishers                                  1
  128003487 roysched                                    1
  400004456 discounts                                   1
  448004627 au_pix                                      1
  496004798 blurbs                                      1
  
(11 rows affected)

用法

使用 sp_helpconstraint 时,还存在一些其它注意事项:

  • sp_helpconstraint 可将外键和参考键截短为 30 个字符。

  • sp_helpconstraint 输出完整性约束的名称和定义,以及该表使用的引用的数目。detail 选项返回有关约束的用户的信息或错误消息。

  • sp_helpconstraint 以类似于一般行内缺省值的显示方式显示共享的行内缺省值。

  • 如果运行 sp_helpconstraint 时不使用任何参数,则将列出当前数据库中包含引用的所有表,并将显示每个表中索引的总数。sp_helpconstraint 基于各表中引用的数目,以降序列出这些表。

  • sp_helpconstraint 只报告有关表的完整性约束信息(由 create table 或 alter table 语句定义)。它不报告使用 create index 语句创建的规则、触发器或索引的有关信息。使用 sp_help 可以查看与表的规则、触发器和索引有关的信息。

  • 对于不具有用户定义的消息的约束,SAP ASE 服务器将报告与约束关联的系统错误消息。查询 sysmessages 可以获取该错误消息的实际文本。

  • 您只能将 sp_helpconstraint 用于当前数据库中的表。

  • 如果查询超过辅助扫描描述符的配置数目,SAP ASE 服务器将返回错误消息。您可以使用 sp_helpconstraint 确定所需扫描描述符的数目。

  • 系统安全员可以防止执行 sp_helpconstraint 的大多数用户看到约束定义的源文本。要将 syscomments 表中 text 列的 select 权限限制给对象所有者或系统管理员,应使用 sp_configure 将 select on syscomments.text column 参数设置为 0。这种权限限制要求在已评估的配置中运行 SAP ASE 服务器。