运行SQL脚本 [英] Running SQL script
问题描述
嗨!
我有一个带有一堆CREATE TABLES,ALTER TABLES的SQL脚本......
我想要它运行transactially。我发现id在一个事务中运行了一个ALTER
STATEMENT,然后将更改消除掉了。
所以如果这适用于一个语句它也应该用于脚本,对吧?
我使用以下命令运行脚本:
db2cmd -c -w -i db2 -t -f SCRIPT.SQL
在此SCRIPT.SQL到数据库的连接后(CONNECT TO DB
的用户....)。
我有什么要尽到一个事务中
$运行此
b $设定b BEST问候,
Kovi
- ?
- 〜 - 〜 - 〜 - 〜 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Gregor Kovac | Gr**********@mikropis.si |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ />
|在一个没有围栏需要盖茨的世界里? |
|体验Linux。 |
- 〜 - 〜 - 〜 - 〜 - 〜 - 〜 - ~~~~~~~~~~~~~~~~~~~~~~ 〜 - 〜 - 〜
" Gregor Kovac" < GR ********** @ mikropis.si>在消息中写道
新闻:Hc ******************** @ news.siol.net ...嗨!
我有一堆创建表,更改表的SQL脚本,...
我想吃炸它transactially运行。我发现我在一个事务中运行了一个ALTER
STATEMENT,然后将更改消除掉。
所以,如果这适用于一个语句,它也适用于脚本,对吧?
我使用以下命令运行脚本:
db2cmd -c -w -i db2 -t -f SCRIPT.SQL
在此SCRIPT.SQL中,建立了与数据库的连接(CONNECT TO DB
用户....)。
什么我必须做一个事务中
跑的?
最好的问候,
Kovi 块引用>
尝试使用+ c代替-c,并确保最后提交。
首先你必须关掉AUTOCOMMIT选项。
你可以通过将+ c选项传递给db2解释器来实现这个目的:
db2cmd -c -w -i db2 + c -t -f SCRIPT.SQL
但是你也可以在你的脚本中控制自动提交(我希望b $ b更喜欢):
SCRIPT.SQL:
-----------------
connect到你的db;
使用c关闭更新命令选项;
....
commit;
- Artur Wronski
嗨Arthur,
你能解释一下自动提交的工作原理吗?一个
交易?
假设我有声明db2 + c插入mytable ......
它是如何工作的?我没有得到清晰的画面.....
问候,
RaInDeeR
块引用>
Hi!
I have an SQL script with bunch of CREATE TABLES, ALTER TABLES, ...
I''d like it to run transactially. I have found that id I run a ALTER
STATEMENT inside a transaction and then roll it back the changes disapear.
So if this works for one statement it should also for a script, right ?
I run the script with the following command:
db2cmd -c -w -i db2 -t -f SCRIPT.SQL
In this SCRIPT.SQL the connection to the database is made (CONNECT TO DB
USER ....).
What do I have to do to run this inside a transaction?
Best regards,
Kovi
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
| Gregor Kovac | Gr**********@mikropis.si |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~解决方案"Gregor Kovac" <gr**********@mikropis.si> wrote in message
news:Hc********************@news.siol.net...Hi!
I have an SQL script with bunch of CREATE TABLES, ALTER TABLES, ...
I''d like it to run transactially. I have found that id I run a ALTER
STATEMENT inside a transaction and then roll it back the changes disapear.
So if this works for one statement it should also for a script, right ?
I run the script with the following command:
db2cmd -c -w -i db2 -t -f SCRIPT.SQL
In this SCRIPT.SQL the connection to the database is made (CONNECT TO DB
USER ....).
What do I have to do to run this inside a transaction?
Best regards,
Kovi
Try using +c instead of -c, and make sure you put a commit at the end.
First of all you have to switch off AUTOCOMMIT option.
You can do this by passing +c option to db2 interpreter:
db2cmd -c -w -i db2 +c -t -f SCRIPT.SQL
but you can also control autocommit within your script (which I
prefer):
SCRIPT.SQL:
-----------------
connect to yourdb;
update command options using c off;
....
commit;
-- Artur Wronski
Hi Arthur,
Can u explain the how the auto commit works during a
transaction ?
Suppose i have the statement db2 +c insert into mytable......
how does it work ? I am not getting the clear picture.....
regards,
RaInDeeR
这篇关于运行SQL脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!