Reputation: 225
I have a table named Test with the following columns.
id PK, int, not null
amount money, not null
I want to set a limit on the amount, say, 1000. I don't want anyone to insert a value greater than 1000 in this column. Can anyone help me on how to do this?
Upvotes: 0
Views: 1133
Reputation: 1354
Something like this
CREATE TABLE tablename
(
-------
--------
amount money,
CONSTRAINT chk_amount CHECK (amount <= 1000)
)
Upvotes: 2
Reputation: 26876
You can create check constraint for your table.
alter table dbo.Your_Table with check add constraint your_Table_Amount check (Amount <= 1000)
go
alter table dbo.Your_Table check constraint your_Table_Amount
Upvotes: 0
Reputation: 15389
You can add a check constraint, like this:
ALTER TABLE Test
ADD CONSTRAINT chk_money CHECK (amount<=1000)
Upvotes: 1