0
0

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 3 years have passed since last update.

SQLSERVERで特定のカラム名を含むテーブルを調べる方法

Posted at

動機

SQLServerを使っていて
大量にあるテーブルの中から特定のカラムを含むテーブルを調べたいシーンが時々あります。

ex)データの洗い替えで別テーブルに同じ名前のカラムがないか(他に影響範囲がないか)

やりかた

SQLServerのカタログビューを使うと簡単にできます。

この例では以下の条件を満たす一覧が取得できます。

  • TenantIdもしくはtenant_idを持つテーブル
  • Testが先頭につくテーブルは除く
select t.name, c.name
from sys.tables t
inner join sys.columns c on t.object_id = c.object_id
where (c.name like '%TenantId%' or  c.name like '%tenant_id%')
and t.name not like 'Test%'

参考

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?