更改oracle表中的多列

发布于 2024-10-28 03:16:43 字数 939 浏览 3 评论 0原文

下面的两个脚本(用于更改表格)会产生差异吗??

脚本 1:

alter table ACNT_MGR_HSTRY add DM_BTNUMBER DATA_TYPE ;
alter table ACNT_MGR_HSTRY add DM_BTID DATA_TYPE ;
alter table ACNT_MGR_HSTRY add DM_USERID DATA_TYPE ;
alter table ACNT_MGR_HSTRY add DM_WSID DATA_TYPE ;

脚本 2:

alter table  ACNT_MGR_HSTRY
add
(
DM_BTNUMBER DATA_TYPE,  
DM_BTID DATA_TYPE,
DM_USERID DATA_TYPE,
DM_WSID DATA_TYPE
);

将更新产生差异..???

update OPERATIONAL_UNIT
 set ( BANK_ID=
 ENTY_CODE_ID=
 TIME_ZONE=
 DM_BTNUMBER=
 DM_BTID=
 DM_USERID=
 DM_WSID=
 );
 -----------
 update OPERATIONAL_UNIT set BANK_ID=;
 update OPERATIONAL_UNIT set ENTY_CODE_ID=;
 update OPERATIONAL_UNIT set TIME_ZONE=;
 update OPERATIONAL_UNIT set DM_BTNUMBER=;
 update OPERATIONAL_UNIT set DM_BTID=;
 update OPERATIONAL_UNIT set DM_USERID=;
 update OPERATIONAL_UNIT set DM_WSID=;

Will the two scripts below (for altering a table) make diff..??

script 1 :

alter table ACNT_MGR_HSTRY add DM_BTNUMBER DATA_TYPE ;
alter table ACNT_MGR_HSTRY add DM_BTID DATA_TYPE ;
alter table ACNT_MGR_HSTRY add DM_USERID DATA_TYPE ;
alter table ACNT_MGR_HSTRY add DM_WSID DATA_TYPE ;

script 2 :

alter table  ACNT_MGR_HSTRY
add
(
DM_BTNUMBER DATA_TYPE,  
DM_BTID DATA_TYPE,
DM_USERID DATA_TYPE,
DM_WSID DATA_TYPE
);

will update makes a diff..???

update OPERATIONAL_UNIT
 set ( BANK_ID=
 ENTY_CODE_ID=
 TIME_ZONE=
 DM_BTNUMBER=
 DM_BTID=
 DM_USERID=
 DM_WSID=
 );
 -----------
 update OPERATIONAL_UNIT set BANK_ID=;
 update OPERATIONAL_UNIT set ENTY_CODE_ID=;
 update OPERATIONAL_UNIT set TIME_ZONE=;
 update OPERATIONAL_UNIT set DM_BTNUMBER=;
 update OPERATIONAL_UNIT set DM_BTID=;
 update OPERATIONAL_UNIT set DM_USERID=;
 update OPERATIONAL_UNIT set DM_WSID=;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷清清 2024-11-04 03:16:43

这两个示例是等效的

我只使用过像第一个示例中那样的语句;我不知道如果在发生错误时使用第二种示例格式,您是否可能不会收到同样好的错误消息。。加里·迈尔斯证实了我的信念:

基本相同。例如,如果 DM_WSID 已经存在,则相关语句将失败。在脚本 1 中,您将添加三列。在脚本 2 中你不会。如果您有 DDL 触发器或 AUDIT,那么对于情况 1,它们将被多次触发。脚本 1 将提交多次,并且可以多次等待独占表锁。

The two examples are equivalent.

I've only ever used statements like you have in the first example; I don't know if it's possible that you won't get as good an error message if using the second example format in the event of an error.. Gary Myers confirmed my belief:

Mostly the same. If, for example, DM_WSID already existed then the relevant statement would fail. In script 1, you'd get three of the columns added. In script 2 you wouldn't. If you have DDL triggers or AUDIT, then they will get fired multiple times for case 1. Script 1 will commit multiple times and MAY wait for an exclusive table lock several times.

薄荷→糖丶微凉 2024-11-04 03:16:43

脚本 2 通常会比脚本 1 执行得更好。将相似的更改分组并同时执行它们几乎总是更快。但真正的问题是,差异显着吗?

根据您对 50 个表(每个表有 15 列)的评论,我认为差异至少有些显着,并且可能非常显着,具体取决于您的配置。

就在昨天,我做了几乎完全相同的更改,修改了大约 100 个表的大约 30 列。使用 SQL*Plus 在本地运行脚本,时间从 2 分钟减少到 4 秒。大部分时间可能都花在了 SQL*Plus 和数据库之间的通信上。如果您有一个需要远程运行的 SQL*Plus 脚本,这些往返可能会使您的脚本极其缓慢。

Script 2 will generally perform much better than script 1. Grouping similar changes and performing them all at once is almost always faster. But the real question is, is the difference significant?

Based on your comment about 50 tables with 15 columns each, I'd say the difference is at least somewhat significant, and possibly very significant depending on your configuration.

Just yesterday I made almost the exact same change, modifying about 30 columns for about 100 tables. Running the script locally using SQL*Plus, the time decreased from 2 minutes to 4 seconds. Most of the time was probably spent communicating between SQL*Plus and the database. If you have a SQL*Plus script that needs to be run remotely those round trips could make your script painfully slow.

苏佲洛 2024-11-04 03:16:43

我们可以通过将需要更改的每一列括起来来修改列的另一种方法。
这里是实例:-

Alter table news 
modify (Newsid        number   primary key              )
modify (newsArticleNo number   check (newsArticleNo > 0))
modify (NewsArea      char(15) default ''               ); 

One more way we can Modify our Columns by bracketing each column that we need to alter it .
Here The instance :-

Alter table news 
modify (Newsid        number   primary key              )
modify (newsArticleNo number   check (newsArticleNo > 0))
modify (NewsArea      char(15) default ''               ); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文