标签: timestamp

为什么时间戳并不总是随着并发插入而增加?

我看到时间戳(rowversion) 列出现了一些意外行为。我创建了一个测试表:

create table Test
(
    Test_Key int identity(1,1) primary key clustered,
    Test_Value int,
    Test_Thread int,
    ts timestamp
)

create nonclustered index IX_Test_Value on Test (Test_Value) -- probably irrelevant
Run Code Online (Sandbox Code Playgroud)

我启动了两个线程同时运行插入到这个表中。第一个线程正在运行以下代码:

declare @i int = 0
while @i < 100
begin
    insert into Test (Test_Value, Test_Thread) select n, 1 from dbo.fn_GenerateNumbers(10000)
    set @i = @i + 1
end
Run Code Online (Sandbox Code Playgroud)

第二个线程正在运行相同的代码,只是它正在select n, 2从函数中插入其线程 ID。

先说一下函数。这使用了一系列带有 ROW_NUMBER() 的交叉连接的公共表表达式来非常快速地按顺序返回大量数字。我从Itzik Ben-Gan的一篇文章中学到了这个技巧,所以要归功于他。我认为函数的实现并不重要,但无论如何我都会包含它:

CREATE FUNCTION dbo.fn_GenerateNumbers(@count int)
RETURNS TABLE WITH SCHEMABINDING
AS …
Run Code Online (Sandbox Code Playgroud)

sql-server concurrency sql-server-2008-r2 timestamp

2
推荐指数
1
解决办法
5160
查看次数

如何将 TIMESTAMP 的默认值设置为未来日期?

我知道我可以像这样使用当前时间戳设置默认值

... DEFAULT CURRENT_TIMESTAMP
Run Code Online (Sandbox Code Playgroud)

有没有办法根据当前时间戳设置具有固定单位数量的列?

... DEFAULT CURRENT_TIMESTAMP + 10 days?
Run Code Online (Sandbox Code Playgroud)

mysql timestamp default-value

2
推荐指数
1
解决办法
6204
查看次数

Should I split timestamp parts into separate columns?

I am building a PostgreSQL database and I have created a timestamp table, where the primary key is the timestamp itself (e.g. id: Fri Apr 13 2018 15:00:19). The database is supposed to be later migrated to a data warehouse, from which analytics will be extracted.

At this point, I am wondering whether it is beneficial to add extra columns to the timestamp table, containing the parsed metrics such as the example below, or have a single table with …

postgresql performance database-design optimization timestamp query-performance

2
推荐指数
2
解决办法
301
查看次数

如何在 SQL Server 中将时间戳/行版本转换为日期和时间?

如何在 SQL Server 中将时间戳/行版本转换为日期和时间?

我有几个表,我想在其中跟踪上次更新,列名称如ModifiedAt, UpdatedAt, UpdatedDate

如果它们使用 Rowversion 数据类型或 Timestamp 数据类型,这可能吗?

CREATE TABLE dbo.Customer (
    CustomerID BIGINT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
    CustomerName NVARCHAR(200) NOT NULL ,
    CreatedAt DATETIME2 NOT NULL CONSTRAINT df_Customer_CreatedAt DEFAULT GETUTCDATE(),
    UpdatedAt ROWVERSION NOT NULL /* does this work ? */
) 
Run Code Online (Sandbox Code Playgroud)

sql-server timestamp

1
推荐指数
1
解决办法
2万
查看次数

Postgres 自动插入带时区的时间戳(印度)

有没有办法在插入查询时自动插入带区域的时间戳?(就像 id 自动递增,因为我不想在 sql 中传递参数作为时间,如果我们使用 zone,则每个地方都相同)。pg 9.1 版。以及如何使用所需的时间格式?

postgresql timestamp postgresql-9.1 timezone

1
推荐指数
1
解决办法
1万
查看次数

19 位数字的最佳最小数据类型大小是多少?

我正在使用此代码来混合日期和时间以将其用作唯一 ID

DateTime.Now.ToString("yyyyMMddHHmmssfffff")
Run Code Online (Sandbox Code Playgroud)

在 SQL Server 2017 中,我很困惑我可以使用哪种数据类型的最佳最小大小来存储此字符串。

最好的最小数据类型是什么:bigint,timestampvarchar(19)?

sql-server datatypes timestamp sql-server-2017

1
推荐指数
1
解决办法
248
查看次数

在 postgres 中获取当前毫秒

我正在我的应用程序中处理时间戳/日期时间。我正在使用 postgres 数据库。在 postgres 中获取当前毫秒(例如 1412706599000)的方法是什么?

postgresql timestamp datetime date time

-1
推荐指数
1
解决办法
4988
查看次数