Friday Philosophy – A Comment on Comments September 25, 2009
Posted by mwidlake in development, internals.Tags: data dictionary, design, documentation, system development
trackback
This blog is not about blog comments. It’s about table and column comments in the data dictionary.
Some of you may well be going “huh?”. Others are probably going “Oh yes, I remember them?”. Table and column comments appear to be suffering the same fate as ERDs, who’s slow demise I bemoaned a couple of weeks ago. They are becoming a feature not known about or used by those with “less personal experience of history” {ie younger}.
It’s a simple principle, you can add a comment against a table or a column,up to 4000 characters. {you can also add comments against index types, materialized views and operators (huh?), at least in 10.2}.
comment on table widlakem.person is 'Test table of fake people for training purposes, approx 50k records' Comment created. select * from dba_tab_comments where owner='WIDLAKEM' and table_name = 'PERSON' OWNER TABLE_NAME TABLE_TYPE ---------- ------------------------------ ----------- COMMENTS -------------------------------------------------------------------------- WIDLAKEM PERSON TABLE Test table of fake people for training purposes, approx 50k records -- comment on column widlakem.person.second_forename is 'null allowed, second or middle name. If more than one, delimited by / character' select * from dba_col_comments where owner='WIDLAKEM' and table_name = 'PERSON' and column_name='SECOND_FORENAME' OWNER TABLE_NAME COLUMN_NAME ---------- ------------------------------ ------------------------------ COMMENTS ------------------------------------------------------------------------------- WIDLAKEM PERSON SECOND_FORENAME null allowed, second or middle name. If more than one, delimited by / character
So you can stick basic information into the data dictionary where it will remain with the object until the object is dropped or the comment is updated. (You can’t drop a comment, you can only update it to ”:
>comment on table widlakem.person is ”;
It’s simple, it’s sensible, it’s solid.
And it seems to be dying out. In fact, I had stopped adding comments to my tables and columns as no one else seemed to bother. Probably as a consequence of them not being added, no one ever seemed to think to look at them to get hints about the database structure and table/column use.
But Raj sitting next to me is as old a hand at this game as myself and I “caught” him adding comments to the little schema we are working on together. Well, if he is bothering, so will I!
How about Oracle Corp? How do they manage on this front? After all, the Oracle Reference manual has all these short descriptions of tables and columns in the data dictionary {some helpful, some utterly unhelpful}:
select owner,count(*) from dba_tab_comments where owner in ('SYS','SYSTEM','SYSMAN') group by owner OWNER COUNT(*) ---------- ---------- SYSTEM 151 SYSMAN 472 SYS 3894 3 rows selected.
Heyyyy, nice Oracle.
select owner,table_name,comments from dba_tab_comments where owner in ('SYS','SYSTEM','SYSMAN') OWNER TABLE_NAME ---------- ------------------------------ COMMENTS ----------------------------------------------------- SYS ICOL$ SYS CON$ SYS FILE$ SYS UET$ SYS IND$ SYSTEM MVIEW_RECOMMENDATIONS This view gives DBA access to summary recommendations SYSTEM MVIEW_EXCEPTIONS This view gives DBA access to dimension validation results SYSTEM AQ$_QUEUE_TABLES SYS SEG$ SYS COL$ SYS CLU$ SYSTEM SQLPLUS_PRODUCT_PROFILE SYSTEM PRODUCT_PRIVS SYSTEM HELP SYSMAN MGMT_NOTIFY_QTABLE SYSMAN AQ$MGMT_NOTIFY_QTABLE_S
Oh. Lots of blanks. Not so nice Oracle. No, scrub that, several lines are not blank, so Not a bad attempt Oracle.
Why all the blanks? Why have Oracle set blank comments? That’s because a blank table comment gets created when you create a table, and a blank column comment is created per column.
create table mdw_temp (col1 number); Table created. select * from dba_tab_comments where table_name = 'MDW_TEMP'; OWNER TABLE_NAME TABLE_TYPE ---------- ------------------------------ ----------- COMMENTS ---------------------------------------------------------------------- WIDLAKEM MDW_TEMP TABLE 1 row selected. select * from dba_col_comments where table_name='MDW_TEMP'; OWNER TABLE_NAME COLUMN_NAME ---------- ------------------------------ --------------- COMMENTS ------------------------------------------------------------------------- WIDLAKEM MDW_TEMP COL1 1 row selected.
So what populated system-like comments do we have?
select owner,count(*) from dba_tab_comments
where owner in (‘SYS’,’SYSTEM’,’SYSMAN’)
and comments is not null
group by owner
OWNER COUNT(*)
———- ———-
SYSTEM 73
SYSMAN 15
SYS 944
OK, there are some, and as you can see below, some are more useful than others…
OWNER TABLE_NAME ---------- --------------- COMMENTS ---------------------------------------------------------------------------------------------------- SYS SYSTEM_PRIVILEG E_MAP Description table for privilege type codes. Maps privilege type numbers to type names SYS TABLE_PRIVILEGE _MAP Description table for privilege (auditing option) type codes. Maps privilege (auditing option) type numbers to type names SYS STMT_AUDIT_OPTI ON_MAP Description table for auditing option type codes. Maps auditing option type numbers to type names SYS RESOURCE_MAP Description table for resources. Maps resource name to number SYS SESSION_PRIVS Privileges which the user currently has set SYS SESSION_ROLES Roles which the user currently has enabled. SYS ROLE_SYS_PRIVS System privileges granted to roles SYS ROLE_TAB_PRIVS Table privileges granted to roles SYS ROLE_ROLE_PRIVS Roles which are granted to roles Oracle_DatabaseInstance contains one entry for each Oracle Instance that is centrally managed. A Real Application Cluster has one entry for each of the instances that manipulate it. Instances of Oracle_DatabaseInstance are created using the database instances that are known to the Oracle Enterprise Manager repository. SYS DBA_AUDIT_OBJECT Audit trail records for statements concerning objects, specifically: table, cluster, view, index, se uence, [public] database link, [public] synonym, procedure, trigger, rollback segment, tablespace, r ole, user SYS USER_AUDIT_OBJECT Audit trail records for statements concerning objects, specifically: table, cluster, view, index, se uence, [public] database link, [public] synonym, procedure, trigger, rollback segment, tablespace, r ole, user SYSMAN ORACLE_DATABASESTATISTICS Oracle_DatabaseStatistics provides current information about the statistics for a database. Database statistics pertain to the database and have the same value regardless of the database instance that is used. SYSMAN ORACLE_DBINSTANCESTATISTICS Oracle_DBInstanceStatistics contains statistics for a database instance. These are retrieved from the Oracle Managment Repository that is managing the database upon request from a managment client.
If you don’t add comments to tables and comments, you will just have blank entries for them in the data dictionary.
So why not pop a few real comments in there, especially for any tables or comments where the name is not really telling you what that column or table is for? It’s free and easy, and it might just prove useful. And if you add them to your tables, I’ll add them to mine.
I like comments. Wish you could create them as part of the CREATE TABLE / ALTER TABLE syntax though.
That’s a very good point Gary, and something I was going to mention. Maybe Comments have dropped out of fashion as you can’t put them into the table create/alter statement.
Maybe we should raise it as an enhancement for Oracle 12.
Comments are so under utilised it’s unreal – not only are people not creating them but just as importantly how often do people look for them?
I think I’ll raise it with the dev team today!