본문 바로가기

sql server

[ms sql] DB, 테이블, 필드 목록 조회

-- DB목록
select name, database_id, create_date from sys.databases

-- 테이블정보
select * from information_schema.tables where table_type='BASE TABLE'
select * from sysobjects where type = 'U' order by name

-- 필드정보
select * from INFORMATION_SCHEMA.COLUMNS where table_name = 'post'
select * from SYSCOLUMNS WHERE ID = OBJECT_ID('post')
sp_columns 'post'