如何在SQL Server中查找非空约束的名称 [英] How to find the name of not-null constraints in SQL Server

查看:147
本文介绍了如何在SQL Server中查找非空约束的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SQL Server中找到命名的非空约束的名称?我可以找到检查约束,默认约束,FK约束,PK约束和唯一约束,但是NN约束让我望而却步。

How can I find the name of a named not-null constraint in SQL Server? I can find check constraints, default constraints, FK constraints, PK constraints and unique constraints, but the NN constraint has eluded me.

推荐答案

您不能。

虽然语法确实接受名称...

Whilst the syntax does accept a name...

CREATE TABLE T
(
C INT CONSTRAINT NN NOT NULL
)

...,并将其解析并验证为名称...

... and it is parsed and validated as a name ...

CREATE TABLE T
(
C INT CONSTRAINT NN123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 NOT NULL
)
/* The identifier that starts with 'NN1234...6' is too long. Maximum length is 128. */

...然后将其忽略,并且实际上不存储在任何位置

... this is then ignored and isn't actually stored anywhere.

与其他约束不同,没有为 sys.objects 添加任何行。它只是存储为关联列的bit属性,而不是约束对象。

No row is added to sys.objects for these unlike other constraints. It is just stored as a bit property of the associated column rather than a constraint object.

这篇关于如何在SQL Server中查找非空约束的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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