SQL在单个命令中在表中添加列和注释 [英] SQL to add column and comment in table in single command
问题描述
我正在将Oracle 11g用于我的Web应用程序.我想向现有表添加列和注释.我可以使用以下命令轻松做到这一点
I am using Oracle 11g for my web application. I want to add a column and a comment to an existing table. I can do that easily with the below commands
ALTER TABLE product ADD product_description VARCHAR2(20)
和
COMMENT ON COLUMN product.product_description
IS 'This is comment for the column';
但是我想在单个命令中完成上述任务.我在互联网上搜索了一个命令,以在单个命令中添加列和注释,但找不到.我想知道这是否可能.任何建议将不胜感激.
But I want to do above task in single command. I searched on internet for a command to add a column and comment in a single command but I couldn't find. I wonder if this is possible. Any suggestions would be highly appreciated.
推荐答案
不,你不能.
没有任何理由需要这样做.这是一次操作,因此只需额外的一两秒钟即可真正键入并执行.
There's no reason why you would need to. This is a one-time operation and so takes only an additional second or two to actually type and execute.
如果您要在Web应用程序中添加列,则这更表明您的数据模型存在缺陷,因为您不需要这样做.
If you're adding columns in your web application this is more indicative of a flaw in your data-model as you shouldn't need to be doing it.
响应您的评论,评论是列属性;它可能似乎,所以Oracle在后台将其存储为 object 的属性.
In response to your comment that a comment is a column attribute; it may seem so but behind the scenes Oracle stores this as an attribute of an object.
SQL> desc sys.com$
Name Null? Type
----------------------------------------- -------- ----------------------------
OBJ# NOT NULL NUMBER
COL# NUMBER
COMMENT$ VARCHAR2(4000)
SQL>
该列是可选的,sys.col$
不包含注释信息.
The column is optional and sys.col$
does not contain comment information.
我不知道,我这样做是为了只有一个处理评论的系统,而不是多个.
I assume, I have no knowledge, that this was done in order to only have one system of dealing with comments rather than multiple.
这篇关于SQL在单个命令中在表中添加列和注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!