0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

通番管理テーブルを使用して通番の取得をする

Posted at

よくある社員データ管理アプリケーションで

  • 部署
  • 社員
    それぞれのデータ登録時に取得する最新の通番を、通番管理テーブルから取得するようにした。

◇前提

  • autoCommitはfalse
  • トランザクション分離レベルはREAD_COMMITTED

◆通番管理テーブル使用前
select max(hogeId)で最大の通番を取得し、+1の通番を登録時に使用。

◆通番管理テーブル使用後
取得と同時に通番管理テーブルの通番を更新しトランザクション開始、本当に更新したいテーブルにデータをinsert後commit。
これで、トランザクション中に別ユーザが通番管理テーブルを更新しようとしても待ちの状態になり、不整合は発生しない。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?