开发者

insert 0 rows without error

Can an insert ever execute without error but not insert anything? I am using sql server 2008 and wondering if I can get away with just checking @@error or is there something I am missing. For an update I check @@error and @@rowcount. Having @@rowcount = 0 for an insert just seems strange to me.

edit @Gregory I basically wondering how I should error check an insert statement. Are there an开发者_开发技巧y strange boundary cases where an insert execute and @@error is 0?


You can run an INSERT command using a select that returns an empty table.

The statement will succeed but no rows updated.

INSERT INTO myTable (col1, col2)
SELECT col1, col2
FROM myOtherTable
WHERE 1 = 2


Are you experiencing no errors, but no insert?

Or is this just a question on why you should use ROWCOUNT? ROWCOUNT has other purposes than checking whether or not a single insert worked.

Or are you asking about @@ERROR?


Additionally, an insert could end up inserting no rows without an error if there is an instead of trigger involved.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜