重命名 SQL Server 中的约束?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8712875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rename a constraint in SQL Server?
提问by mezamorphic
Is it possible to rename a constraint in SQL Server? I don't want to have to delete and create a new one because this constraint affects other already existing constraints and I will have to recreate/alter those.
是否可以重命名 SQL Server 中的约束?我不想删除并创建一个新的,因为这个约束会影响其他已经存在的约束,我将不得不重新创建/更改它们。
采纳答案by gbn
回答by ozz
回答by rojib
answer is true :
答案是正确的:
exec sp_rename
@objname = 'Old_Constraint',
@newname = 'New_Constraint',
@objtype = 'object'
回答by Winks
I know this is an old question, but I just found the following to be very helpful, in addition to the other great answers:
我知道这是一个老问题,但我发现除了其他很棒的答案之外,以下内容非常有帮助:
If the constraint to be renamed has a period in it (dot), then you need to enclose it in square brackets, like so:
如果要重命名的约束中有句点(点),则需要将其括在方括号中,如下所示:
sp_rename 'schema.[Name.With.Period.In.It]', 'New.Name.With.Period.In.It'