user12074577
user12074577

Reputation: 1419

Set a number value limit in SQL

I am new to SQL, and I have a table group with a group_cap column. How do I specify in SQL that column group_cap cannot be a value greater than 4. For example, there cannot be more than 4 people in group A.

Upvotes: 0

Views: 193

Answers (1)

jhinkley
jhinkley

Reputation: 668

Create a constraint on the table.

ALTER TABLE [group] ADD CONSTRAINT
    CK_group_cap CHECK (group_cap <= 4)

for a range of values, use between

ALTER TABLE [group] ADD CONSTRAINT
    CK_group_cap CHECK (group_cap between 1 and 4)

Upvotes: 1

Related Questions