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

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

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

問題描述

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

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.

有沒有辦法在直線插入中增加時(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í)被稱為運(yùn)行時(shí)常量.查詢中對(duì)函數(shù)的每個(gè)引用在運(yùn)行時(shí)都會(huì)評(píng)估一次,但在整個(gè)查詢執(zhí)行過程中,每一行都獲得相同的值.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.

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

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:

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

我有沒有提到您應(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)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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)名稱“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(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 欧美日韩免费在线观看 | 亚洲一区视频 | 久久久久久九九九九 | 久草网站| 久久久久网站 | 人人插人人爽 | 91性高潮久久久久久久久 | 精品第一页 | 综合伊人久久 | 男女交配网站 | 国产精品久久久精品 | av天天看| 日本视频一区二区三区 | 国产欧美精品一区二区色综合 | 激情五月综合色婷婷一区二区 | 97caoporn | 国产精品一区二区在线免费观看 | 欧美色综合 | 国产欧美一区二区精品性色超碰 | 日本www视频 | 国产福利视频在线观看 | 窝窝午夜精品一区二区 | 色天堂影院 | 亚洲视频一区 | 成人动漫在线观看 | 亚洲精品视频免费观看 | 国产视频一二区 | 成人在线观看网站 | 成年人视频在线播放 | 中文字幕亚洲精品 | 午夜天堂网 | 日韩视频免费在线观看 | 国产农村妇女精品一二区 | 黄网免费看 | 一区二区三区在线免费 | 亚洲精品久久久久avwww潮水 | 中文在线字幕免费观看 | 日韩色黄大片 | 欧美日韩精品久久久免费观看 | 在线观看成人免费视频 | 一区二区水蜜桃 |