コメント(テーブル、カラム)

select * from ALL_TAB_COMMENTS where table_name = 'TAB1';
select * from ALL_COL_COMMENTS where table_name = 'TAB1' and column_name = 'COL1';


comment on table test.tab1 is 'comment on tab1';
comment on column test.tab1.col1 is 'comment on tab1.col1';

 

https://tanamon.hatenablog.jp/entry/20090325/1237972922

show table status like 'tab1';
show full columns from tab1;

CREATE TABLE tab1 (
col1 int comment 'comment on tab1.col1',
col2 int comment 'comment on tab1.col2'
)
comment='comment on tab1';


ALTER TABLE tab1 COMMENT 'new comment on tab1';

ALTER TABLE tab1 MODIFY col1 int COMMENT 'new comment on tab1.col1';

 

select
  table_name
, table_comment
from information_schema.tables
where table_schema= 'test'
and table_name = 'tab1'
;


select
  ordinal_position
, column_name
, column_comment
from information_schema.columns 
where table_schema= 'test'
and table_name = 'tab1'
order by ordinal_position
;

 

 

\dt+ tab1
\d+ tab1

comment on table tab1 is 'comment on tab1';
comment on column tab1.col1 is 'comment on tab1.col1';

 


https://lightgauge.net/database/sqlserver/3010/


SELECT
t.name AS table_name
,ep.value AS comment
FROM
sys.tables AS t
,sys.extended_properties AS ep
WHERE
t.name = 'tab1'
AND t.object_id = ep.major_id
AND ep.minor_id = 0
go

SELECT
t.name AS table_name
,c.name AS column_name
,ep.value AS commnet
FROM
sys.tables AS t
,sys.columns AS c
,sys.extended_properties AS ep
WHERE
t.name = 'tab1'
AND t.object_id = c.object_id
AND c.object_id = ep.major_id
AND c.column_id = ep.minor_id
go

EXEC sys.sp_addextendedproperty @name=N'MS_Description'
,@value=N'comment on tab1'
,@level0type=N'SCHEMA'
,@level0name=N'dbo'
,@level1type=N'TABLE'
,@level1name=N'tab1'
go

EXEC sys.sp_addextendedproperty @name=N'MS_Description'
,@value=N'comment on tab1.col1'
,@level0type=N'SCHEMA'
,@level0name=N'dbo'
,@level1type=N'TABLE'
,@level1name=N'tab1'
,@level2type=N'COLUMN'
,@level2name=N'col1'
go