我对 sql 完全陌生(有几天时间来了解它)并且有以下问题:
这是约束的语法:
在创建表格时,我有这样一行:
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.
关于sql - 关于约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27898448/