在表格中间插入新列? [英] Inserting new columns in the middle of a table?

查看:117
本文介绍了在表格中间插入新列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用ALTER TABLE选项卡ADD col时,新列将添加到表的末尾。例如:

When one uses "ALTER TABLE tab ADD col", the new column gets added to the end of the table. For example:

TABLE: TAB
COL_1 COL_2 COL_4

ALTER TABLE TAB ADD COL_3

表将成为

TABLE: TAB
COL_1 COL_2 COL_4 COL_3

我的示例列表明我实际上喜欢这个表结束像这样:

However as the naming of my example columns suggests I'd actually like the table to end up like this:

TABLE: TAB
COL_1 COL_2 COL_3 COL_4 

COL_4之前的COL_3。

With COL_3 before COL_4.

除了从头重建表,有没有任何标准的SQL将完成工作?但是,如果没有标准的SQL,我仍然可以使用一些供应商依赖的解决方案为Oracle,但再次标准的解决方案是最好的。

Besides rebuilding the table from scratch, is there any standard SQL that will get the job done? However if there is no standard SQL, I could still use some vendor dependent solutions for Oracle, but again a standard solution would be best.

谢谢。 b $ b

推荐答案

默认情况下,列仅在结尾添加。

By default, columns are only added at the end.

在中间,你必须删除并重新创建表和所有相关对象(约束,索引,默认值,关系等)。

To insert a column in the middle, you have to drop and recreate the table and all related objects (constraints, indices, defaults, relationships, etc).

几个工具为你做这些,并且根据表的大小,这可能是一个密集的操作。

Several tools do this for you, and depending on the size of the table, this may be an intensive operation.

您还可以考虑在表上创建视图,按照优先顺序显示列表中的实际顺序)。

You may also consider creating views on the table that display columns in the order of preferrence (overriding the actual order in the table).

这篇关于在表格中间插入新列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆