Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 SQL 新手,我有一个带有 group_cap 列的表组。如何在SQL中指定group_cap列的值不能大于4。例如A组不能超过4人。
在表上创建一个约束。
ALTER TABLE [group] ADD CONSTRAINT CK_group_cap CHECK (group_cap <= 4)
对于一系列值,使用between
between
ALTER TABLE [group] ADD CONSTRAINT CK_group_cap CHECK (group_cap between 1 and 4)