sp_helptext <objname>[, <grouping_num>][, <numlines>[, <printopts>]]]
<objname>
是要显示其源文本的编译对象的名称。编译对象必须在当前数据库中。
<grouping_num>
是在 <objname> 表示一组过程时标识单个过程的整数。该参数告知 sp_helptext 显示组中指定过程的源文本。
在使用 <printops> 参数时,该参数还指定生成 SQL 文本的起始行。
> 注意
> 视图、缺省值和其它非过程对象是永远不被分组的;只将 <number> 用于过程组。
<numlines>
指定要为其生成 SQL 文本的行数。如果还将参数 <printopts> 与 showsql 一起使用,<numlines> 将指定要显示的 SQL 文本的行数;如果将 <printopts> 与 context 一起使用,<numlines> 将被视为起始行号周围的上下文块宽度。
<printopts>
支持逗号分隔的输出格式属性,由用户选择。可按逗号分隔字符串的形式以任意顺序指定一个或多个这种输出选项:
<printopts> 列表中,将不调用此属性。
(/*<nnn>*/),因此如果需要,生成的 SQL 仍可用于重新创建编译对象,而无需进行进一步的编辑。
<numlines> 参数或该参数为空,则会提供包括五行的缺省上下文块(在相关行号前后生成)。
use <database> 命令和 drop <object> 命令开始输出。这允许您几乎完全重新生成在重新创建大多数编译对象(例如过程、触发器、视图、缺省值以及规则)时所需的 SQL。
输出选项 ddlgen 和 context 是互斥的指示符。如果一起使用,将引发错误。若要在显示 SQL 文本的上下文块时获取行号,请使用 context 和 linenumbers 指示符。
显示 pub_idrule 的源文本。因为此规则在 pubs2 数据库中,所以从 pubs2 执行此命令:
sp_helptext pub_idrule
<h2># Lines of Text</h2>
1
<h2>text</h2>
create rule pub_idrule
as @pub_id in ("1389", "0736", "0877",
"1622", "1756")
or @pub_id like "99[0-9][0-9]"
显示 sp_helptext 的源文本。因为系统过程存储于 sybsystemprocs 中,所以从 sybsystemprocs 执行此命令:
sp_helptext sp_helptext
显示 myproc 组行为(其中未指定 <number> 参数)的源文本。过程编号显示在文本旁:
sp_helptext myproc
<h2># Lines of Text</h2>
2
number
<h2>text</h2>
1
create procedure myproc; as select 1
2
create procedure myproc;2 as select 2
(2 rows affected)
显示 myproc 的源文本,并且指定 <myproc> 组中的过程,但不显示分组数。
sp_helptext myproc, 2
<h2># Lines of Text</h2>
1
<h2>text</h2>
create procedure myproc;2 as select 2
为 sp_help 生成文本:
sp_helptext sp_help,NULL,NULLM 'showsql'
若要为 sp_help 生成文本并生成行号:
sp_helptext sp_help, NULL,NULL,'showsql,linenumbers'
若要在始于行 25 的 7 行上下文块中为 sp_help 生成文本,并在注释块中生成输入:
sp_helptext sp_help,25,7,'showsql,comments,context'
为 sp_droptabledef 生成文本,并以可用于重现此过程的独立 DDL 脚本形式生成输出:
<h2>sp_helptext sp_droptabledef,NULL,NULL,'showsql,ddlgen'</h2>
use sybsystemprocs
</h2>
IF EXISTS (SELECT 1 FROM sysobjects
WHERE name = 'sp_droptabledef'
AND type = 'P'
<h2>DROP PROCEDURE sp_droptabledef</h2>
/*Sccsud="%Z%generic/sproc/src/%M%%I%%G%"*/
/*
**Omni only
*/
create procedure sp_droptabledef
@tablename varchar(92) /*tablename*/
as begin
declare @status int
exec @status = sp_dropobjectdef @tablename
return(@status)
<h2>end</h2>
(return status = 0)
对使用分隔标识符创建的视图使用 sp_helptext。不需要使用 set quoted_identifier on 即可提取定义视图的 SQL。但是,需要它使用分隔标识符创建对象:
<h2>set quoted_identifier ON</h2>
create table "t one"
(c1 int,
"c two" varchar(10),
<h2> "c three int)</h2>
create table "t two"
("t2 one" int,
"t2 two" varchar(10),
<h2> t2_three int)</h2>
create view "v one" as
select * from "t one"
UNION
select "t2 one","t2 two",t2_three
<h2> from "t two"</h2>
SAP ASE 服务器显示谓词的文本。包括谓词的用户定义名称(如果存在)或其具有 sp_helptext 的内部名称:例如:
sp_helptext pred1
<h1>Lines of Text</h1>
---------------
1
text ----------------------------------------------------
grant select on tab1 where col1 = 5 as pred1 to robert
使用 sp_helptext 时,还存在一些其它注意事项:
select* 语句,则它通常会反映此语句引用的表的整个列列表。
select * 语句,则在 SAP ASE 服务器向 syscomments 中写入文本后,显示的扩展列列表将具有带中括号的标识符。例如:
[this column], [column name with space]
对于自身为分隔标识符或使用分隔标识符的编译对象,在为其生成文本时无需 set quoted_identifier ON。