使用 Informix 在单次往返中执行多个语句
是否可以使用 Informix 和 .Net 在单次往返中运行多个 DML 语句?
示例(当然这不起作用):
var cmd = someIfxConnection.CreateCommand();
cmd.CommandText = @"
insert into Foo(Bar, Baz) values (1, 2);
insert into Foo(Bar, Baz) values (3, 4);";
cmd.ExecuteNonQuery();
Is it possible to run multiple DML statements in a single roundtrip using Informix and .Net?
Example (of course this doesn't work):
var cmd = someIfxConnection.CreateCommand();
cmd.CommandText = @"
insert into Foo(Bar, Baz) values (1, 2);
insert into Foo(Bar, Baz) values (3, 4);";
cmd.ExecuteNonQuery();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,Informix 允许您执行多个 INSERT/UPDATE 语句,如示例中所示。您不能执行包含 SELECT 的多个语句。
例如,在 SQL Server 中,常见的代码如下:
这可以在单个命令中执行,并将从新插入的记录中返回自动递增的主键值。
然而,这在 Informix 中不起作用。您必须执行两个不同的 SQL 命令。一种用于插入记录,另一种用于从 systables 表中检索 Id:
As far as I'm aware, Informix allows you to perform multiple INSERT/UPDATE statements as you have in your example. What you CANNOT do is perform multiple statements that contain a SELECT.
For example, in SQL Server it is common to see code as follows:
This can be performed in a single command and would return the auto-incrementing primary key value from the newly inserted record.
This does not work within Informix however. You have to perform two distinct SQL commands. One to insert the record and one to retrieve the Id from the systables table: