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

使用遞增的時(shí)間戳執(zhí)行插入

Perform insert with timestamp that increments(使用遞增的時(shí)間戳執(zhí)行插入)
本文介紹了使用遞增的時(shí)間戳執(zhí)行插入的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我有一個(gè)腳本將幾十萬(wàn)條記錄插入到一??個(gè)表中.其中一列是 DATETIME2(7),我將 SYSUTCDATETIME() 插入其中.問(wèn)題是每條記錄都具有相同的確切時(shí)間戳.我試圖避免執(zhí)行游標(biāo)或 while 循環(huán),而只是執(zhí)行一個(gè)不錯(cuò)的快速插入/選擇語(yǔ)句.

I have a script inserting a few hundred thousand records into a table. One of the columns is a DATETIME2(7), and I'm inserting SYSUTCDATETIME() into it. The problem is that every single record has the same exact time stamp. I'm trying to avoid doing a cursor or while loop, and just perform a nice fast insert into/select from kind of statement.

有沒(méi)有辦法在直線插入中增加時(shí)間,即使是納秒?例如

Is there a way to have the time increment, even it it's by nano seconds, in a straight insert? e.g.

INSERT INTO [dbo].[Users]
     ( [FirstName]
     , [LastName]
     , [CreatedDate] )
SELECT  [DI].[FirstName] AS [FirstName]
      , [DI].[LastName]  AS [LastName]
      , SYSUTCDATETIME() AS [CreatedDate]
FROM    [dbo].[DataImport] AS [DI];

推薦答案

這些函數(shù)有時(shí)被稱(chēng)為運(yùn)行時(shí)常量.查詢(xún)中對(duì)函數(shù)的每個(gè)引用在運(yùn)行時(shí)都會(huì)評(píng)估一次,但在整個(gè)查詢(xún)執(zhí)行過(guò)程中,每一行都獲得相同的值.SQL Server 認(rèn)為這是一個(gè)特性而不是一個(gè)bug.

These functions are sometimes referred to as runtime constants. Each reference to the function in the query is evaluated once at runtime, but each row gets the same value fro the entire query execution. SQL Server considers this a feature not a bug.

你能做什么?那么第一件事就是不要依賴(lài)時(shí)間戳來(lái)進(jìn)行這種區(qū)分.使用 identity 列來(lái)唯一標(biāo)識(shí)每一行.那么,這將不是問(wèn)題.

What can you do? Well the first thing is to simply not rely on a timestamp for this differentiation. Use an identity column to uniquely identify each row. Then, this won't be an issue.

如果出于某種原因,您確實(shí)必須使用日期/時(shí)間列,那么您可以創(chuàng)建自己的常量.例如:

If, for some reason, you do have to use the date/time column, then you can make up your own constant. For instance:

dateadd(microsecond, row_number() over (order by (select null)), SYSUTCDATETIME()

時(shí)間不準(zhǔn)確.但我們?cè)谶@里談?wù)摰氖俏⒚?你可以使用納秒).

The timing isn't accurate. But we are talking microseconds here (and you could use nanoseconds).

這確實(shí)做出了關(guān)鍵假設(shè):

This does make key assumptions:

  • 您沒(méi)有時(shí)間可能重疊的并發(fā)插入.
  • 您沒(méi)有及時(shí)執(zhí)行插入操作,以免出現(xiàn)重疊.

我有沒(méi)有提到您應(yīng)該使用 identity 列代替?

Did I mention that you should be using an identity column instead?

這篇關(guān)于使用遞增的時(shí)間戳執(zhí)行插入的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱(chēng)“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號(hào)或管道運(yùn)算符字符串中刪除重復(fù)項(xiàng))
Change an iterative query to a relational set-based query(將迭代查詢(xún)更改為基于關(guān)系集的查詢(xún))
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 99re视频这里只有精品 | 一区在线观看视频 | 精品久久伊人 | 亚洲在线| 欧美日韩亚洲三区 | 日日爱夜夜操 | 国产精品99视频 | 精品亚洲一区二区 | 国产人成精品一区二区三 | 97中文视频| 国产成人精品一区二区三区在线 | 小h片免费观看久久久久 | 91网站在线播放 | 日本在线视频中文字幕 | 天天操操操操操 | 久久久久久久久久久丰满 | 成人国产免费观看 | 福利片在线 | 日韩毛片在线观看 | 美女视频一区二区三区 | 欧美午夜精品 | 九九看片 | 日韩视频在线观看中文字幕 | 91一区二区| 一级毛片中国 | 国产色婷婷久久99精品91 | 精品一区免费 | 天天操夜夜艹 | 亚洲精品久久久蜜桃 | 黄色一级大片在线观看 | 色婷婷综合久久久久中文一区二区 | 日韩免费福利视频 | 久久国产一区二区 | 成人午夜免费福利视频 | 一区二区三区av | 成人不卡 | 久久久成人一区二区免费影院 | 超碰97免费观看 | 亚洲永久免费观看 | 在线欧美视频 | 欧美日韩综合视频 |