Can there be constraints with the same name in a DB?

后端 未结 6 1269
逝去的感伤
逝去的感伤 2020-12-10 00:39

This is a follow-on question from the one I asked here.

Can constraints in a DB have the same name?

Say I have:

CREATE TABLE Employer
(
    E         


        
6条回答
  •  隐瞒了意图╮
    2020-12-10 01:03

    I was always puzzled why constraint names must be unique in the database, since they seem like they're associated with tables.

    Then I read about SQL-99's ASSERTION constraint, which is like a check constraint, but exists apart from any single table. The conditions declared in an assertion must be satisfied consistently like any other constraint, but the assertion can reference multiple tables.

    AFAIK no SQL vendor implements ASSERTION constraints. But this helps explain why constraint names are database-wide in scope.

提交回复
热议问题