使用绑定规则和默认值替换已弃用的 SQL Server 用户定义类型
我们有一个用户定义的数据类型 YesNo,它有一个 char(1) 的别名。该类型具有绑定规则(必须是 Y 或 N)和默认值 (N)。
这样做的目的是,当任何开发团队创建 YesNo 类型的新字段时,规则和默认值会自动绑定到新列。
规则和默认值已被弃用,并且在 SQL Server 的下一个未来版本中不可用,是否有其他方法可以实现相同的功能?
我应该补充一点,我知道我可以使用 CHECK 和 DEFAULT 约束来复制绑定 Rule 和 Defalut 对象的功能,但是这些必须在每次使用该类型时应用,而不是“免费”获得功能' 通过使用具有绑定规则和默认值的 UDT。
这篇文章涉及支持现有应用程序的数据库,而不是新开发的数据库,因此我知道我们对 UDT 的使用并不是最佳的。
我怀疑这个问题的答案是“否”,但是通常当功能被弃用时,通常会有一种替代语法可以用作替换,所以我想提出这个问题,以防有人知道替代方案。
We have a User Defined Data Type of YesNo which has an which is an alias for char(1). The type has a bound Rule (must be Y or N) and a Default (N).
The aim of this is that when any of the development team create a new field of type YesNo the rule and default are automatically bound to the new column.
Rules and Defaults have been deprecated and won't be available in the next a future version of SQL Server, is there another way to achieve the same functionality?
I should add that I'm aware that I could use CHECK and DEFAULT constraints to replicate the functionality of the bound Rule and Defalut objects, however these would have to be applied at each usage of the type, rather than getting the functionality 'for free' by using a UDT which has a bound Rule and Default.
The post relates to a database that backs an existing application, rather than a new development, so I'm aware that our use of UDT's is less than optimal.
I suspect the answer to the question is 'No', however normally when features are deprecated there's usually an alternative syntax that can be used as a drop in replacement so I wanted to pose the question in-case someone knew of an alternative.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认和检查约束...
就我个人而言,我倾向于不使用UDT(上次是SQL Server 6.5 IIRC),因为没有ALTER TYPE以防万一发生任何变化...
至于弃用..
首先在 CREATE RULE for SQL Server 2005。所以,我们被告知 6 年以及 3 个版本之前的
SQL Server 2000。 ..
这同样适用于 创建默认值,对象而不是约束< /em>
那是11年前的事了
Default and check constraints...
Personally, I tend not to use UDTs (last time was SQL Server 6.5 IIRC) because there is no ALTER TYPE in case anything changes...
As for deprecation..
First mentioned in CREATE RULE for SQL Server 2005. So, we were told 6 years and 3 releases ago
For SQL Server 2000...
The same applies to CREATE DEFAULT, the object not the constraint
That's 11 years ago
“规则和默认值已被弃用,并且在下一版本的 SQL Server 中将不再可用”
1) 据我所知,这不是真的。你不可能突然破坏 99.9% 的 TSQL!
2)此外,即使这是真的(我坚信不是),弃用并不意味着在下一个版本中删除,只是一个功能不应再在新代码中使用。
您有此类公告的官方链接吗?
用户@gbn 似乎认为我正在捍卫已弃用的结构的使用。我不是。
"Rules and Defaults have been deprecated and won't be available in the next version of SQL Server"
1) As far as I know that is not true. You cannot suddenly break 99.9% of TSQL out there!
2) Also, even if it were true (and I strongly believe it is not), deprecated does not mean removed in the next release, simply that a feature should no longer be used in new code.
Do you have an official link to any such announcement?
User @gbn seems to think I am defending the use of deprecated constructs. I am not.
对于如此简单的事情使用 Xquery 有点迟钝。我通常将它用于更复杂的数据输入,但它确实(我认为)回答了您有关替换的问题。以下是我如何将参数实现为类型化 xml,该参数必须为 true 或 false。您可以将其扩展为是/否或小狗/小猫或任何您想要的。
Xquery is a bit obtuse to use for something this simple. I typically use it for more complex data typing, but it does (I think) answer your question regarding a replacement. Here is how I might implement a parameter as typed xml which must be either true or false. You can extend it to be yes/no or puppy/kitten or whatever you'd like.