sql server management studio未显示完整的选定数据

idfiyjo8  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(342)

我使用下面的代码为 Item_Id =1 日期之间 2010-06-16 以及 2010-06-17 :

SELECT * 
FROM [System_SiteAzure].[dbo].[Values]
WHERE ([Timestamp] BETWEEN '2010-06-16' AND '2010-06-17')
  AND ([Item_Id] = 1)

但是,我意识到有些行丢失,这意味着所选数据不完整。我是sql新手,我想知道为什么会发生这种情况?谢谢
例如,这是我使用上述代码选择后获得的数据的一部分:

Id    Timestamp               Values  Item_Id
36409897    2010-06-16 16:00:57.870 40      1
36409898    2010-06-16 16:01:00.993 39.5    1
36410345    2010-06-16 16:10:07.207 39      1
36410346    2010-06-16 16:10:10.333 38.5    1
36410731    2010-06-16 16:19:29.267 38      1
36410732    2010-06-16 16:19:32.393 37.5    1
36414061    2010-06-16 17:41:00.487 37.5    1
36414062    2010-06-16 17:41:03.613 39.5    1
36414065    2010-06-16 17:41:06.740 40.5    1
36414070    2010-06-16 17:41:09.863 41      1
36414071    2010-06-16 17:41:12.990 41.5    1
36414232    2010-06-16 17:45:26.893 42      1
36414233    2010-06-16 17:45:30.017 42.5    1

而对于相同的时间间隔,完整的数据应该如下所示:

Timestamp   Values
16:00:01    47.5
16:00:04    48
16:02:03    47.5
16:02:06    47
16:03:37    46.5
16:03:40    46
16:05:27    45.5
16:05:30    45
16:07:36    44.5
16:07:39    44
16:09:35    43.5
16:09:38    43
16:11:59    42.5
16:12:03    42
16:15:42    41.5
16:15:45    41
16:18:19    40.5
16:18:22    40
16:19:47    39.5
16:19:50    42
16:19:54    43
16:19:57    44
16:20:00    44.5
16:20:03    45
16:22:24    44.5
16:22:27    44
16:23:46    43.5
16:23:49    43
16:26:04    42.5
16:26:08    42
16:30:10    41.5
16:30:14    41
16:33:03    40.5
16:33:06    40
16:36:12    39.5
16:36:15    39
16:40:41    38.5
16:40:45    38
16:43:09    38.5
16:43:12    42
16:43:15    43
16:43:18    43.5
16:43:21    44
16:46:43    43.5
16:46:46    43
16:49:13    42.5
16:49:16    42
16:53:00    41.5
16:53:03    41
16:55:46    40.5
16:55:49    40
16:58:45    39.5
16:58:48    39
17:03:00    38.5
17:03:03    38
17:06:08    37.5
17:06:11    37
17:06:34    36.5
17:06:37    36
17:12:26    35.5
17:12:29    35
17:16:54    34.5
17:16:57    34
17:23:26    33.5
17:23:30    33
17:25:01    33
17:25:04    34
17:25:07    36
17:25:10    41.5
17:25:14    43
17:25:17    44
17:25:20    44.5
17:25:23    45
17:25:52    45.5
17:25:55    46
17:27:39    46.5
17:27:42    47
17:28:04    46.5
17:28:07    46
17:30:09    45.5
17:30:12    44.5
17:30:25    45
17:30:28    45.5
17:32:31    45
17:32:34    44.5
17:35:27    44
17:35:30    43.5
17:37:39    44
17:37:42    44.5
17:37:46    45
17:37:49    45.5
17:41:37    45
17:41:40    44.5
17:44:11    44
17:44:14    43.5
17:46:41    43

我可能错过了一些功能吗?

xu3bshqb

xu3bshqb1#

开始使用rowversion,因为时间戳已被弃用。

CREATE TABLE ExampleTable2 (PriKey int PRIMARY KEY, VerCol rowversion) ;

默认情况下,sqlmanagementstudio只显示1000行。检查sql是否为“select top 1000”。移除顶部1000。但我看到你把整个sql都放在那里了。所以问题出在查询上。检查timestamp是否为timestamp类型,它是否有如下数据

RowID   TimeStamp   SmallDateTime   DateTime
1   AAAAAAAAB9E=

CREATE TABLE MyTestTable(RowID INT IDENTITY(1,1) NOT NULL,
[TimeStamp] TIMESTAMP, [SmallDateTime] SMALLDATETIME,
[DateTime]  DATETIME)
INSERT INTO MyTestTable([SmallDateTime],[DateTime])VALUES(GETDATE(), GETDATE())

SELECT * FROM MyTestTable

ROWVERSION and TIMESTAMP Overview
Summary information:

Syntax  ROWVERSION  Available since SQL Server 2005
TIMESTAMP   Deprecated 
Generated Numbers   Unique within a database
Storage Size    8 bytes
Internal Representation BINARY(8)   For non-nullable
VARBINARY(8)    For nullable
Number of Columns Allowed   One per table

相关问题