如何更改SQL Server中列的现有规则 [英] How to alter the existing rule on a column in SQL server

查看:84
本文介绍了如何更改SQL Server中列的现有规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How to Alter the Existing Rule on a Column in SQL Server





创建规则[dbo ]。[AccountStatus]为@AccountStatus in('A','C','N','T','I','D','F','M')





我想绑定更多状态



我尝试了什么:



ALTER规则[dbo]。[AccountStatus]为@AccountStatus in('A','C','N','T','I', 'D','F','M',

'X','R','Y')



Create rule [dbo].[AccountStatus] as @AccountStatus in ('A','C','N','T','I','D','F','M')


I want to Bind more Statuses

What I have tried:

ALTER rule [dbo].[AccountStatus] as @AccountStatus in ('A','C','N','T','I','D','F','M',
'X','R','Y')

推荐答案

I得到解决方案,这里是



需要遵循4个步骤。



1)放弃现有规则

2)取消绑定现有规则

3)创建新规则

4)绑定新规则



I got the Solution, here it is

4 steps need to be followed.

1)Drop the existing rule
2)Unbind the existing Rule
3)Create the New Rule
4)Bind the New Rule

DROP RULE [AccountStatus] as @AccountStatus

EXEC sp_unbindrule 'BsmasterAcnt.AccountStatus'

EXEC sp_bindrule  'AccountStatus','Bsmasteracnt.AccountStatus'


删除规则并创建更正的规则: DROP RULE(Transact-SQL) [ ^ ]



但更重要的是你不应该使用RULE语句。这是一种旧语法,将在不久的将来删除。而不是规则。使用约束:唯一约束和检查约束 [ ^ ]
You drop the rule and create the corrected one: DROP RULE (Transact-SQL)[^]

But more importantly you should not use RULE statement. This is an old syntax which will be removed in the near future. Instead of rules. use constraints: Unique Constraints and Check Constraints[^]


这篇关于如何更改SQL Server中列的现有规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆