0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ストアドやビューの名前と内容を検索する方法【SQLServer】

Posted at
sp_helptext '名前'

これでは一つずつしか検索できずに不便な時がある。

一度に関連するストアドを検索したり、検索したい内容が決まっている場合などに便利。

SELECT sysobjects.type
      ,sysobjects.name
      ,sys.sql_modules.definition
FROM sys.sql_modules
LEFT OUTER JOIN sysobjects
ON sysobjects.id = sys.sql_modules.object_id
ORDER BY sysobjects.type

後は WHERE句 で条件指定してあげればOK。
タイプを指定することが多いかと。
P:ストアドプロシージャ
V:ビュー
みたいな感じで。

ちなみに、ストアドプロシージャとストアドファンクションのみの場合、
ROUTINE_DEFINITION を使用できるが、定義の最初の4,000文字しか検索できないので注意が必要。

SELECT ROUTINE_TYPE
      ,ROUTINE_NAME
      ,ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
ORDER BY ROUTINE_TYPE
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?