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

SQL Server 如何在標識列中生成值?

How does SQL Server generate values in an identity column?(SQL Server 如何在標識列中生成值?)
本文介紹了SQL Server 如何在標識列中生成值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的問題是,如果我有兩個并行的批量插入到一個表中,SQL Server 如何創建標識值?

My question is if I have two batch inserts into one table in parallel, how does SQL Server create identity values?

我的意思是,如果在一個會話中我插入多行(Row1-Row2-Row3),同時另一個會話同時插入多行(Row4-Row5-Row6),結果會是這樣嗎?

I mean, if in one session I insert multiple rows (Row1-Row2-Row3) and simultaneously another session inserts multiple rows (Row4-Row5-Row6) at the same time, the result would be like this?

Row1
Row2
Row3
Row4
Row5
Row6

或者類似的東西?

Row1
Row6
Row3
Row5
Row4
Row2

推薦答案

您犯了假定表格中的順序的常見謬誤.表沒有順序.只有結果才有順序,除非指定了明確的 ORDER BY,否則順序是不確定的.

You are making the common fallacy of assuming an order in the table. Tables have no order. Only results have order, which is undetermined unless an explicit ORDER BY is specified.

您可能會問一個不同的問題:在并發插入的情況下,如何分配標識生成的值?答案很簡單:沒關系.如果您對訂單做出任何假設,那么您的代碼就會被破壞.間隙也是如此.即使生成的身份完全隨機,您的應用程序也應該可以運行,如果身份完全隨機,正確編寫的應用程序運行.使用 SCOPE_IDENTITY() 檢索最后一個插入的身份.更好的是,使用 OUTPUT 子句INSERT,它也適用于多行插入.

You may ask a different question: how is the identity generated value assigned in case of concurrent inserts? The answer is simple: it doesn't matter. And if you make any assumption about the order then your code is broken. Same goes for gaps. Your application should work even if the identities generated are completely random, and correctly written application will work if the identity is completely random. Use SCOPE_IDENTITY() to retrieve the last inserted identity. Better still, use the OUTPUT clause of INSERT, it works for multi-row inserts too.

為了記錄:身份是按照操作獲得對日志流.

For the record: the identities are generated in the order on which operations acquire access to the log stream.

這篇關于SQL Server 如何在標識列中生成值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 久久久久国产 | 亚洲最大的成人网 | www.99热.com| 国产在线精品一区二区三区 | 91久久综合| 日韩在线视频一区二区三区 | 日韩一区二区福利视频 | 中文字幕日韩一区 | 日韩一区二区三区精品 | 日韩欧美成人一区二区三区 | 国产日韩欧美一区二区 | 久久久久久久久久久久久久久久久久久久 | 一区二区三区四区在线视频 | 亚洲成人免费 | 欧美a在线 | 久久美女视频 | 欧美一区二不卡视频 | 久久美国| 成人免费网视频 | 久久久久久国产精品 | 久久久国产一区 | 久久中文网 | 一区二区免费 | 国产高潮av | 国产乱码精品一区二区三区忘忧草 | 精品久久香蕉国产线看观看亚洲 | 国产精品久久久久久久岛一牛影视 | 在线视频 亚洲 | 天天操天天拍 | 久久成人18免费网站 | 欧美精品片| 欧美成人精品一区二区男人看 | 久久久精品一区二区三区 | 欧美成人a∨高清免费观看 91伊人 | 午夜国产 | 在线看黄免费 | 国产亚洲精品美女久久久久久久久久 | 男女午夜激情视频 | 国产成人免费视频 | 日韩高清一区 | 午夜精品视频在线观看 |