您好,登錄后才能下訂單哦!
小編給大家分享一下SqlServer 2008如何創(chuàng)建測試數(shù)據(jù),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
包含要點: 數(shù)據(jù)庫的循環(huán) 、 insert select 句式 、 隨機(jī)數(shù)(rand()函數(shù))、絕對值(abs()函數(shù))
DECLARE @starttime varchar(50) DECLARE @endtime varchar(50) DECLARE @randomvalue float SET @starttime='2017-09-15 00:15:00.000' SET @endtime='2017-10-20 00:00:00.000' -- set @randomvalue=floor(rand()*10) -- -- select CONVERT(varchar(50), DATEADD(mi,15,@starttime),121) --select [TagID],[Value]-@randomvalue,[StartValue]-@randomvalue,CONVERT(varchar(50),DATEADD(mi,15,[StartTime]),121),[EndValue]-@randomvalue,CONVERT(varchar(50),DATEADD(mi,15,[EndTime]),121) --from [dbo].[DimTagMinuteData] where TagID in (1, -- 2,3,4,5,6, -- 7,8,9,10,11, -- 12,13,14,15,16, -- 17,18,19,20 -- ) --and StartTime=@starttime and EndTime=CONVERT(varchar(50),DATEADD(mi,15,@starttime),121) WHILE @starttime<=@endtime begin set @randomvalue=floor(rand()*10) IF @starttime<=@endtime BEGIN insert INTO DimTagMinuteData ([TagID],[Value],[StartValue] ,[StartTime] ,[EndValue] ,[EndTime]) select [TagID] , ABS([Value]-@randomvalue) , ABS([StartValue]-@randomvalue), CONVERT(varchar(50),DATEADD(mi,15,[StartTime]),121), ABS([EndValue]-@randomvalue), CONVERT(varchar(50),DATEADD(mi,15,[EndTime]),121) from [dbo].[DimTagMinuteData] where TagID in (1, 2,3,4,5,6, 7,8,9,10,11, 12,13,14,15,16, 17,18,19,20 ) and StartTime=@starttime and EndTime=CONVERT(varchar(50),DATEADD(mi,15,@starttime),121) end else begin print 'stop' end set @starttime= CONVERT(varchar(50), DATEADD(mi,15,@starttime),121) end -- 隨機(jī)數(shù) select floor(rand()*100)當(dāng)然 循環(huán)的時候 可以不用 if else 判斷
以上是“SqlServer 2008如何創(chuàng)建測試數(shù)據(jù)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。