简体   繁体   English

在T-Sql中使用用户定义的数据类型识别所有存储过程和表

[英]Identifying all stored procedures and tables using a User-Defined Data Type in T-Sql

I'm using SSMS and I have a User-Defined Data Type which was created in the early 2000 with a rule object attached to it. 我正在使用SSMS,并且有一个用户定义的数据类型,该数据类型是在2000年初创建的,其中附加了一个规则对象。

Many tables and stored procedures use this User-Defined Data Type as a type. 许多表和存储过程都将此用户定义的数据类型用作类型。 I want to alter these tables and stored procs to take out this UDT so I can replace them with check constraints, but I'm having trouble identifying all the tables and stored procs in which this UDT is used as a type. 我想更改这些表和存储的proc以取出此UDT,以便可以用检查约束替换它们,但是我在识别所有使用该UDT作为类型的表和存储的proc时遇到了麻烦。

I've been looking at old scripts and using sp_help table_name to seek out these instances, but I was wondering if there's a way to find all the tables/columns and stored procs which use a certain user-defined data type. 我一直在寻找旧脚本,并使用sp_help table_name查找这些实例,但是我想知道是否存在一种方法来查找所有使用某种用户定义数据类型的表/列和存储的proc。

Thank you. 谢谢。

EDIT: I figured out how to find all the uses of user-defined data types on tables 编辑:我想出了如何找到表上用户定义的数据类型的所有使用

SELECT TABLE_NAME, COLUMN_NAME, DOMAIN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE DOMAIN_NAME = 'UDT_name'

For stored procedures, I removed my discovered method because NicVerAZ linked a better way to accomplish this below. 对于存储过程,我删除了发现的方法,因为NicVerAZ在下面链接了一种更好的方法来完成此操作。

Refer to the article below on how to properly search for a string in a stored procedure definition: 请参阅下面的文章,了解如何在存储过程定义中正确搜索字符串:

Search text in stored procedure in SQL Server 在SQL Server中的存储过程中搜索文本

As I posted in a comment above, ROUTINE_DEFINITION is an NVARCHAR(4000) and longer stored procedures have their definition truncated. 正如我在上面的评论中所述,ROUTINE_DEFINITION是NVARCHAR(4000),更长的存储过程的定义被截断了。

Your second method is not bad, it gets it done but yes your first is more correct. 您的第二种方法不错,可以完成,但是是的,第一种方法更正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM