久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在僅附加表中設(shè)置版本列

Setting version column in append only table(在僅附加表中設(shè)置版本列)
本文介紹了在僅附加表中設(shè)置版本列的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我們有一個表來存儲記錄的版本.

We have a table that will store versions of records.

列是:

Id (Guid)
VersionNumber (int)
Title (nvarchar)
Description (nvarchar)
etc...

保存項(xiàng)目將在表中插入一個新行,該行具有相同的 Id 和遞增的 VersionNumber.

Saving an item will insert a new row into the table with the same Id and an incremented VersionNumber.

我不確定如何最好地生成連續(xù)的 VersionNumber 值.我最初的想法是:

I am not sure how is best to generate the sequential VersionNumber values. My initial thought is to:

SELECT @NewVersionNumber = MAX(VersionNumber) + 1
FROM VersionTable
WHERE Id = @ObjectId

然后在我的插入語句中使用@NewVersionNumber.

And then use the the @NewVersionNumber in my insert statement.

如果我使用這種方法,是否需要將我的事務(wù)設(shè)置為可序列化以避免并發(fā)問題?我不想最終得到相同 ID 的重復(fù)版本號.

If I use this method do I need set my transaction as serializable to avoid concurrency issues? I don't want to end up with duplicate VersionNumbers for the same Id.

有沒有更好的方法來做到這一點(diǎn),而不是讓我使用可序列化的事務(wù)?

Is there a better way to do this that doesn't make me use serializable transactions?

推薦答案

為了避免并發(fā)問題(或在您的特定情況下重復(fù)插入),您可以創(chuàng)建一個復(fù)合鍵作為表的主鍵,由 ID 組成和 VersionNumber 列.然后,這將對鍵列強(qiáng)制執(zhí)行唯一約束.

In order to avoid concurrency issues (or in your specific case duplicate inserts) you could create a Compound Key as the Primary Key for your table, consisting of the ID and VersionNumber columns. This would then enforce a unique constraint on the key column.

隨后,您的插入例程/邏輯可以設(shè)計(jì)為處理或捕獲由于重復(fù)鍵導(dǎo)致的插入錯誤,然后簡單地重新發(fā)出插入過程.

Subsequently your insert routine/logic can be devised to handle or rather CATCH an insert error due to a duplicate key and then simply re-issue the insert process.

還值得一提的是,除非您特別需要使用 GUID,即因?yàn)槭褂?SQL Server 復(fù)制或多個數(shù)據(jù)源,否則您應(yīng)該考慮使用替代數(shù)據(jù)類型,例如 BIGINT.

It may also be worth mentioning that unless you specifically need to use a GUID i.e. because of working with SQL Server Replication or multiple data sources, that you should consider using an alternative data type such as BIGINT.

這篇關(guān)于在僅附加表中設(shè)置版本列的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標(biāo)記轉(zhuǎn)換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 亚洲精品日韩在线 | 日韩欧美国产一区二区三区 | 91精品国产91久久久久久 | 男人阁久久| 999久久久久久久 | 日韩视频在线播放 | 视频一区二区在线观看 | 国产高清视频一区 | 一区二区高清 | 成人亚洲精品 | 国产视频第一页 | 免费午夜视频在线观看 | 日韩精品一区二区三区在线观看 | 99久久电影 | 久久性色| 久草网站 | 黄色精品| 超碰激情| 自拍视频在线观看 | 国产综合视频 | 国产欧美精品一区二区 | 伊人伊成久久人综合网站 | 综合国产 | 狠狠色综合久久丁香婷婷 | 秋霞a级毛片在线看 | 亚洲一区二区黄 | 亚州av| 亚洲欧美久久 | 天天操精品视频 | 欧美一区二区三区久久精品视 | 精品中文字幕一区二区 | 91精品久久久久 | 美女张开腿露出尿口 | 美女天天干天天操 | 一区二区三区观看视频 | 最新中文字幕久久 | 久久精品福利 | 中文字幕不卡视频在线观看 | 国产精品a久久久久 | 国产中文区二幕区2012 | aaa综合国产 |