如何保证100%插入成功(insert into)

伊凡yifan 2007-12-25 12:12:59
我是用ASP的SQL语句执行插入的


用的SQL SERVER 2000
数据库没有报任何错。我插入完后未检查是否插入成功。没想到查日志的时侯发现有一些记录并未插入进去的情况。

死锁的情况不清楚如何查
程序和数据库都是在一台服务器上。本地程序写本地数据库

可能量小的时侯可能也有这方面问题

SQL语句是标准写法:insert into

asp是多用户访问方式,每个用户访问都会进行insert into操作
...全文
184 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gimse7en 2007-12-25
  • 打赏
  • 举报
回复
mark
rouqu 2007-12-25
  • 打赏
  • 举报
回复
每次insert后面判断@@error值 不为0即插入失败 然后把错误程序交回asp处理
伊凡yifan 2007-12-25
  • 打赏
  • 举报
回复
我说清楚一下:程序未作任何改动下,insert into 数据写不进去的情况是随机出现的。
说明程序没问题,而是sql server 2000的问题
rouqu 2007-12-25
  • 打赏
  • 举报
回复
When Microsoft® SQL Server™ completes the execution of a Transact-SQL statement, @@ERROR is set to 0 if the statement executed successfully. If an error occurs, an error message is returned. @@ERROR returns the number of the error message until another Transact-SQL statement is executed. You can view the text associated with an @@ERROR error number in the sysmessages system table.

Because @@ERROR is cleared and reset on each statement executed, check it immediately following the statement validated, or save it to a local variable that can be checked later.
rouqu 2007-12-25
  • 打赏
  • 举报
回复
check the @@error system parameter after the DML statement(s)
rouqu 2007-12-25
  • 打赏
  • 举报
回复
插入操作一般没什么问题 如果表有主外键、unique约束、check 会导致一些失败

让数据库来确保99.99%是成功的
-------------
只要符合规则 100%能插 本身不存在失误的可能

伊凡yifan 2007-12-25
  • 打赏
  • 举报
回复
能否不由程序来判断插入结果,让数据库来确保99.99%是成功的?
难道
微软就这么垃圾??

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧