是否有包含 RowVersion 值的 Microsoft.SqlServer.Management.Smo.SqlDataType 的替代方案?

发布于 2024-08-25 11:17:56 字数 515 浏览 1 评论 0原文

Microsoft.SqlServer.Management。 Smo.SqlDataType 枚举具有 timestamp 类型的值,但没有 rowversion 类型的值。我正在寻找程序集的更新版本或支持它的替代枚举类型。

现有枚举具有 Timestamp 值,但根据 rowversion 文档timestamp 已“已弃用,并将在未来版本中删除”。我更喜欢避免使用已弃用的东西:)

The Microsoft.SqlServer.Management.Smo.SqlDataType enum has a value for the timestamp type but not rowversion. I'm looking for an updated version of the assembly or an alternate enum type that supports it.

The existing enum has a value for Timestamp, but according to the rowversion documentation, timestamp is "deprecated and will be removed in a future version". I prefer to avoid using deprecated things :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深居我梦 2024-09-01 11:17:57

我找不到任何表明 SqlDataType.Timestamp 已弃用的信息。您提供的链接表明,rowversion 的“timestamp 语法”在 T-SQL 中已弃用,您应该使用 rowversion 来代替,但它由库维护者负责确保在他们的产品中实现正确的语法。如果时间戳语法在未来版本中实际上被删除,那么我确信该库将被更新,并且 Timestamp 枚举值仍将向后兼容使用它的代码。由于它们不提供 RowVersion 枚举值,我只使用 Timestamp

I can't find anything that indicates that SqlDataType.Timestamp is deprecated. The link you provide indicates that the "timestamp syntax" for rowversion is deprecated in T-SQL and that you should use rowversion instead, but it is up to the library maintainers to make sure that the correct syntax is implemented in their product. Should it come to pass that the timestamp syntax is actually removed in a future version, then I'm sure the library will be updated and the Timestamp enumeration value will still be backward compatible for code that uses it. Since they don't provide a RowVersion enumeration value, I would just use Timestamp.

裂开嘴轻声笑有多痛 2024-09-01 11:17:56

快速回答:

不,您不需要使用其他类型。 Microsoft.SqlServer.Management.Smo。 SqlDataType 数据类型是正确使用的类型。尽管是旧式名称,Microsoft.SqlServer.Management.Smo.SqlDataType.Timestamp 是 SMO 针对 行版本

不推荐使用 SQL Sever DDL 语句中的类型名称“timestamp”。如果您的代码生成包含类型名称 timestamp 的 DDL 语句并将其发送到 SQL Server,则应更改代码以使用 [rowversion][4]。但是,如果您只是使用 SMO 或任何使用 Microsoft.SqlServer.Management.Smo.SqlDataType 类型,您不会受到服务器端名称更改的影响。

长答案:

我将在这里合并一些引用,以避免重新发明轮子。首先,来自 http://www.mssqltips.com/tip.asp?tip= 的一些历史记录第1501章

此数据类型 [ROWVERSION] 是
SQL Server 2000 中引入
最终替换时间戳数据
类型。在 ANSI-SQL 定义中,
时间戳被定义为日期和
微软实施它的时间
作为一个每次都会改变的二进制值
时间一行发生变化。微软有
警告使用时间戳会
最终改变为坚持
ANSI 标准,因此其用途
并发管理应该是
避免了。目前,时间戳和
rowversion 类似于每个
其他...

请注意,Oracle 和 Postgres 都以符合标准的方式使用 TIMESTAMP,因此 Microsoft 放弃非标准的时间戳用法是明智之举,以避免让 Oracle 开发人员在 SQL Server 上工作变得更加困难。

无论如何,从 timestamprowversion 的更改只是名义上的。它不会影响使用该类型的列的行为。根据 rowversion 的 MSDN 文档:

时间戳是以下的同义词
rowversion 数据类型并受
数据类型同义词的行为。在
DDL语句,使用rowversion代替
尽可能的时间戳。为了
有关详细信息,请参阅数据类型同义词 (Transact-SQL)。

如果您深入研究数据类型同义词的文档:

所有后续元数据函数
在原始对象上执行并且
任何派生对象都会报告
基本数据类型,而不是同义词。这
行为与元数据一起发生
操作,例如 sp_help 等
系统存储过程,
信息模式视图,或
各种数据访问API元数据
报告数据类型的操作
表或结果集列的数量。

换句话说,当 SMO 获取有关表的元数据时,它只知道行版本。这意味着包含 rowversion 类型列的表将作为 Microsoft.SqlServer.Management.Smo.SqlDataType.Timestamp

SMO API 从未跟上 SQL Server 使用的新命名。但由于类型的底层行为没有改变,只有名称改变,所以您的 SMO 客户端代码不需要改变。

如果您的代码显示 SQL Server 数据类型,您可以成为一个好公民并更改该代码以显示“rowversion”而不是“timestamp”。但除此之外,您的代码根本不需要更改。事实上,大多数 SMO 客户端 (包括 Visual Studio 的表设计工具!)甚至从未费心更改其 UI 以反映新的命名。由于这些 UI 在幕后连接到枚举,因此无论 SQL Server 在 DDL 中调用什么类型,SMO API 客户端都将继续工作。

SMO API 的未来版本也可能会向枚举添加一个具有相同基础数值的同义值(例如 Microsoft.SqlServer.Management.Smo.SqlDataType.RowVersion),但前提是现有客户没有被破坏,这对他们来说可能是一个低优先级。

Quick answer:

No, you don't need to use another type. Microsoft.SqlServer.Management.Smo.SqlDataType datatype is the right type to use. Despite the old-style name, Microsoft.SqlServer.Management.Smo.SqlDataType.Timestamp is the value returned by SMO for SQL Server columns of type rowversion.

What's being deprecated is the use of the type name "timestamp" in SQL Sever DDL statements. If your code is generating DDL statements containing the type name timestamp and sending them to SQL Server, you should change your code to use [rowversion][4] instead. But if you're just using SMO or any of the types which use the Microsoft.SqlServer.Management.Smo.SqlDataType type, you won't be affected by the name change on the server side.

Long Answer:

I'm going to combine a few quotes here to avoid re-inventing the wheel. First, some history from http://www.mssqltips.com/tip.asp?tip=1501:

This data type [ROWVERSION] was
introduced in SQL Server 2000 to
eventually replace the timestamp data
type. In the ANSI-SQL definition,
timestamp is defined as a date and
time whereas Microsoft implemented it
as a binary value that changes every
time a row changes. Microsoft has
warned that the use of timestamp will
eventually be changed to adhere to the
ANSI standard so its use for
concurrency management should be
avoided. Currently, both timestamp and
rowversion are analogous to each
other...

Note that Oracle and Postgres both use TIMESTAMP in the standards-compliant way, so it's a smart move by Microsoft to ditch the non-standard usage of timestamp to avoid making things harder for Oracle devs trying to work on SQL Server.

Anyway, the change from timestamp to rowversion is in name only. It doesn't impact the behavior of columns using that type. Per the MSDN docs for rowversion:

timestamp is the synonym for the
rowversion data type and is subject to
the behavior of data type synonyms. In
DDL statements, use rowversion instead
of timestamp wherever possible. For
more information, see Data Type Synonyms (Transact-SQL).

If you dig into the docs for Data Type Synonyms:

All subsequent metadata functions
performed on the original object and
any derived objects will report the
base data type, not the synonym. This
behavior occurs with metadata
operations, such as sp_help and other
system stored procedures, the
information schema views, or the
various data access API metadata
operations that report the data types
of table or result set columns.

In other words, by the time SMO gets ahold of the metadata about the table, it only knows about rowversion. This means that tables with columns of type rowversion are being returned to SMO as Microsoft.SqlServer.Management.Smo.SqlDataType.Timestamp

The SMO API never caught up with the new naming used by SQL Server. But because the underlying behavior of the type didn't change, only the name, your SMO client code does not need to change.

If your code is displaying SQL Server data types, you can be a good citizen and change that code to display "rowversion" instead of "timestamp". But otherwise your code doesn't need to change at all. In fact, most SMO clients (including Visual Studio's table design tool!) never even bothered to change their UI to reflect the new naming. Because those UIs connect to the enum under the covers, the SMO API clients will continue working regardless of what SQL Server calls the type in DDL.

It's possible that a future rev of the SMO API might also add a synonymous value to the enum (e.g. Microsoft.SqlServer.Management.Smo.SqlDataType.RowVersion) with the same underlying numeric value, but given that existing clients aren't broken this is probably a low priority for them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文