InnoDB约束数据的方法

  • Primary Key / Unique Key
  • Foreign Key
  • Default / Not NULL
  • 触发器

    Primary Key / Unique Key

    通过将字段设置为索引,约束数据内容
    primary key, unique key
    唯一约束插入时的性能开销较大

Foreign Key

  • 外键可以对数据的正确性实现约束

    Default / NOT NULL

  • Default:数据默认值

  • NOT NULL:数据不为空

    触发器

  • 插入、修改数据时,使用触发器校验数据

  • 容易干扰业务,使用很少