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

使用遞增的時間戳執行插入

Perform insert with timestamp that increments(使用遞增的時間戳執行插入)
本文介紹了使用遞增的時間戳執行插入的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個腳本將幾十萬條記錄插入到一??個表中.其中一列是 DATETIME2(7),我將 SYSUTCDATETIME() 插入其中.問題是每條記錄都具有相同的確切時間戳.我試圖避免執行游標或 while 循環,而只是執行一個不錯的快速插入/選擇語句.

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.

有沒有辦法在直線插入中增加時間,即使是納秒?例如

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];

推薦答案

這些函數有時被稱為運行時常量.查詢中對函數的每個引用在運行時都會評估一次,但在整個查詢執行過程中,每一行都獲得相同的值.SQL Server 認為這是一個特性而不是一個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.

你能做什么?那么第一件事就是不要依賴時間戳來進行這種區分.使用 identity 列來唯一標識每一行.那么,這將不是問題.

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.

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

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()

時間不準確.但我們在這里談論的是微秒(你可以使用納秒).

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

這確實做出了關鍵假設:

This does make key assumptions:

  • 您沒有時間可能重疊的并發插入.
  • 您沒有及時執行插入操作,以免出現重疊.

我有沒有提到您應該使用 identity 列代替?

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

這篇關于使用遞增的時間戳執行插入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
主站蜘蛛池模板: 成年人视频免费在线观看 | 成人免费大片黄在线播放 | 色视频网站| 99国内精品久久久久久久 | 三级在线视频 | 日韩欧美国产精品 | 免费看的黄网站 | 国产精品一区二区三级 | 91亚洲精品国偷拍自产在线观看 | 国外成人在线视频 | 久久精品小视频 | 视频一区二区在线观看 | 日本三级日产三级国产三级 | 午夜精品久久久久久久久久久久久 | k8久久久一区二区三区 | 国产精品免费大片 | 国产超碰人人爽人人做人人爱 | 97久久精品午夜一区二区 | 亚洲精品日韩一区二区电影 | 亚洲一区免费视频 | 精品一区二区三区中文字幕 | 国产目拍亚洲精品99久久精品 | 91精品国产高清一区二区三区 | 天天天操天天天干 | 日本视频在线播放 | 久久毛片网站 | 色约约视频 | 日本不卡一区二区三区在线观看 | 久久99精品久久久水蜜桃 | 国产亚洲精品久久情网 | 色婷婷亚洲 | 婷婷色在线播放 | 国产精品久久久久久一区二区三区 | 日韩在线视频一区二区三区 | 久久久久久成人 | 美日韩精品| 欧美一级二级在线观看 | 日韩视频一区在线观看 | 久久精品二区亚洲w码 | 久久久久久亚洲国产精品 | 亚洲国产二区 |