Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle create table with column comments

Tags:

sql

oracle

Is there a column comment syntax that allows me to specify a column comment directly where I declare the column in the create table statement (i.e. inline)? The 11g spec does not mention anything, on another page something is mentioned but I could not get it to work. There is a way to specify comments after creating the table, but I think it is annoying that the comment is separated from the field definition. I am looking for something like this (which does not work):

create table whatever (
 field number(15,0) primary key comment 'primary key generated from sequence pkseq',
 ...
)
like image 569
Hans-Peter Störr Avatar asked May 09 '12 12:05

Hans-Peter Störr


People also ask

What is comment on column in Oracle?

Purpose. Use the COMMENT statement to add a comment about a table, view, materialized view, or column into the data dictionary. To drop a comment from the database, set it to the empty string ' '.

What is comment on column?

Adds, revises, or removes a projection column comment. You can only add comments to projection columns, not to table columns. Each object can have one comment. Comments are stored in the system table COMMENTS .


1 Answers

I'm afraid the "annoying" COMMENT ON syntax is the only way of doing this. SQL Server, PostgreSQL and DB2 use the same syntax (even though, as far as I know, there is no ANSI standard syntax for adding comments to database objects).

MySQL supports the way you would like it to work. I agree it would be a nicer mechanism, but in my experience so few people use comments at all that I doubt Oracle will ever change it.

like image 163
APC Avatar answered Oct 03 '22 04:10

APC