gpt4 book ai didi

sql-server - 向表中添加可为空的 rowversion 列

转载 作者:行者123 更新时间:2023-12-02 23:55:57 28 4
gpt4 key购买 nike

我会保持这个简短而甜蜜。我正在尝试将 rowversion 类型的列添加到现有表中。我的想法是,通过将其添加为 NULL,现有行不会被标记时间戳,但可惜的是。如果是这种行为,那么在什么情况下该列会接受空值?

最佳答案

if they give you the option of making it a nullable type, what is the functional difference between nullable vs non-nullable

实际上,没有功能差异(但可能存在存储差异,请参见下文)。您无法将 NULL 插入到 rowversion 列中。

即使您在 INSERT 语句中为 rowversion 列指定 NULL,服务器也会插入生成的非空值。无论您如何声明 rowversion 列(NULLNOT NULL),它都会像这样工作。

<小时/>

docs仅提及可为空的 rowversion 一次:

A nonnullable rowversion column is semantically equivalent to a binary(8) column. A nullable rowversion column is semantically equivalent to a varbinary(8) column.

如果您指定 rowversion 可为空,它应该占用更多磁盘空间,以允许存储可能的 NULL 值(实际上这不会发生)。每个可为空的列都会产生开销,请参阅:How much size "Null" value takes in SQL Server

In addition to the space required to store a null value there is also an overhead for having a nullable column.

此外,varbinary(8)binary(8) 需要更多的磁盘空间来存储值的长度。

<小时/>

话虽如此,我尝试创建两个表,每个表有 10M 行。第一个具有可为空的 rowversion 列,第二个具有不可为空的 rowversion 列。在我的测试中,两个表占用的磁盘空间量完全相同。我在 SQL Server 2014 Express 上进行了测试。

关于sql-server - 向表中添加可为空的 rowversion 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42215930/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com