关于约束
Concerning Constraints
我对 sql 完全陌生(有几天的时间来了解它)并且有以下问题:
这是约束的语法:
创建 table 时,我有这样一行:
CONSTRAINT smth UNIQUE(name)
我知道它对列 name
施加了约束以使其唯一,但 smth
的用途是什么?为什么我们需要命名约束?它在任何地方都可以使用吗?
你给它命名(和很多东西一样),这样你就可以很容易地在你的数据库中执行维护。
请参阅 ALTER TABLE ... DROP CONSTRAINT 并注意您必须在那里提供约束的 名称。
此外,如果约束条件为 violated:
会很有帮助
An optional name for a column or table constraint. If the constraint is violated, the constraint name is present in error messages, so constraint names like col must be positive can be used to communicate helpful constraint information to client applications.
约束有名称。
很有用。想象一下:
- 当您需要删除约束时
- 当您列出对象的约束时
- 当约束失败时,它会在错误消息中显示名称。
CONSTRAINT constraint_name UNIQUE(column_name)
column_name:您正在对其应用约束
constraint_name:您要应用到的约束的名称column_name
用于标识UNIQUE(present declared)约束,不需要可以删除
我对 sql 完全陌生(有几天的时间来了解它)并且有以下问题:
这是约束的语法:
创建 table 时,我有这样一行:
CONSTRAINT smth UNIQUE(name)
我知道它对列 name
施加了约束以使其唯一,但 smth
的用途是什么?为什么我们需要命名约束?它在任何地方都可以使用吗?
你给它命名(和很多东西一样),这样你就可以很容易地在你的数据库中执行维护。
请参阅 ALTER TABLE ... DROP CONSTRAINT 并注意您必须在那里提供约束的 名称。
此外,如果约束条件为 violated:
会很有帮助An optional name for a column or table constraint. If the constraint is violated, the constraint name is present in error messages, so constraint names like col must be positive can be used to communicate helpful constraint information to client applications.
约束有名称。
很有用。想象一下:
- 当您需要删除约束时
- 当您列出对象的约束时
- 当约束失败时,它会在错误消息中显示名称。
CONSTRAINT constraint_name UNIQUE(column_name)
column_name:您正在对其应用约束
constraint_name:您要应用到的约束的名称column_name
用于标识UNIQUE(present declared)约束,不需要可以删除