正确的隔离级别?

The right isolation level?

假设我有一个存储过程,用于插入有关客户提交的新订单的信息。而且这个存储过程可以被很多不同的用户同时使用。

我的问题是“如果我有这两个隔离级别选项(已提交读和可序列化),应该处理哪种隔离级别的存储过程”?

我需要一个完整的理由,因为我被卡住了,这是最好的决定。

获取该读提交隔离级别的示例将非常有帮助,在并发处理中,如果使用它不会破坏数据库,或者如果使用可序列化隔离级别它会破坏数据库。这意味着我需要通过证明其中之一是正确的决定来理解。

亲切的问候。

Let's consider that I have a stored procedure that inserts information about a new order submitted by a customer. And this stored procedure can be used concurrently by many different users.

由于您只执行插入操作,因此事务本质上是非冲突的。因此,您需要 读取提交的隔离级别。这是默认隔离级别。

来自documentation

Read Committed Isolation Level

In the read committed isolation level, which is the default, every query executed by a transaction sees only data committed before the query—not the transaction—began. This level of isolation is appropriate for database environments in which few transactions are likely to conflict.

Serializable Isolation Level

In the serialization isolation level, a transaction sees only changes committed at the time the transaction—not the query—began and changes made by the transaction itself. A serializable transaction operates in an environment that makes it appear as if no other users were modifying data in the database.

Serializable isolation is suitable for environments:

  • With large databases and short transactions that update only a few rows

  • Where the chance that two concurrent transactions will modify the same rows is relatively low

  • Where relatively long-running transactions are primarily read only