命名为CONSTRAINT好处 [英] Named CONSTRAINT benefits
本文介绍了命名为CONSTRAINT好处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习SQL,偶然发现了CONSTRAINT。我可以这样定义它们:
I'm learning SQL and stumbled about CONSTRAINT. I can define them like this:
CREATE TABLE products (
product_no integer,
name text,
price numeric CHECK (price > 0)
);
并且像这样:
CREATE TABLE products (
product_no integer,
name text,
price numeric CONSTRAINT positive_price CHECK (price > 0)
);
为什么要给他们名字?或为什么我应该或不应该给他们的名字?
我在这个例子中可以看到,在大多数情况下,我不能重用它们。
Why do I give them names? or Why I should or should not give them names? As I can see in this example and most situations in my mind I can't reuse them. So what is the benefit of giving a name to a CONSTRAINT?
推荐答案
为你的约束赋予明确的名字有很大的好处。只有几个示例:
There are significant benefits of giving explicit names to your constraints. Just a few examples:
- 您可以按名称删除它们。
- 如果在选择
名称时使用约定,那么您可以从元表中收集
,并以编程方式处理
。
这篇关于命名为CONSTRAINT好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文