48
62

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 1 year has passed since last update.

SQL Server テーブル一覧取得いろいろ

Last updated at Posted at 2017-05-18

SQL Serverでテーブル一覧に関する情報を取得する。

テーブル一覧取得

全テーブル取得
select * from sys.objects;
ユーザーテーブルだけ
select * from sys.objects where type = 'U';
特定(hoge)のスキーマ配下だけ
select * from sys.objects where schema_id = schema_id('hoge');

##テーブルの行数を一括で求める(PostgreSQL風)

特定(hoge)のスキーマ配下のテーブルの行数を求める
select
  schema_name(SYSOBJ.schema_id) as schemaname,
  SYSOBJ.name as relname,
  SINDEXES.rows as n_live_tup
from sys.objects as SYSOBJ inner join sys.sysindexes as SYSINDEXES on
  SYSOBJ.object_id = SYSINDEXES.id and
  SYSINDEXES.indid < 2
where SYSOBJ.type = 'U'
  and schema_name(SYSOBJ.schema_id) = 'hoge'
order by SYSOBJ.name; 
48
62
2

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
48
62

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?