1
数据库原理与应用技术
1.10.3.3 9.3.3 查看用户定义函数
9.3.3 查看用户定义函数

1. 通过使用SQL Server Management Studio查看用户定义函数

使用 SQL Server Management Studio,在对象资源管理器中查看过程的定义。

(1) 在对象资源管理器中,连接到数据库引擎实例,然后展开该实例。

(2) 展开“数据库”、“过程所属的数据库”及“可编程性”。

(3) 展开“函数”,选择要查看属性的函数的文件夹,右键单击要查看其属性的函数,然后选择“属性”。

(4) 在“函数属性-s_course”对话框中显示属性,如图9-40所示。

图9-40 “函数属性-s_course”对话框

2. 使用语句查看函数的定义和属性

(1) 在对象资源管理器中,连接到数据库引擎实例。

(2) 在标准菜单栏上,选择“新建查询”。

(3) 输入以下代码到查询窗口中(查询s_course的定义),然后选择“执行”。

USE students;

GO

-- Get the function name, definition, and relevant properties

SELECT sm.object_id,

OBJECT_NAME(sm.object_id) AS object_name,

o.type,

o.type_desc,

sm.definition,

sm.uses_ansi_nulls,

sm.uses_quoted_identifier,

sm.is_schema_bound,

sm.execute_as_principal_id

-- using the two system tables sys.sql_modules and sys.objects

FROM sys.sql_modules AS sm

JOIN sys.objects AS o ON sm.object_id = o.object_id

-- from the function 'dbo.ufnGetProductDealerPrice'

WHERE sm.object_id = OBJECT_ID('dbo.s_course')

ORDER BY o.type;

GO

USE students;

GO

-- Get the definition of the function dbo.ufnGetProductDealerPrice

SELECT OBJECT_DEFINITION (OBJECT_ID('dbo.s_course')) AS ObjectDefinition;

GO

执行结果如图9-41所示。

图9-41 查询s_course的执行结果