CHECK constraint in SQL verifies the value in the column to be according to specification.
Example:
- CHECK (Balance >= 1000)
- CHECK (Balance BETWEEN 1000 and 7000)
- CHECK (Balance IN (1000, 2000, 4000, 7000, 9000)
In Query 3, the Balance can have value 1000 or 2000 or 4000 or 7000 or 9000 only.
Note:
- We can impose one or more constraint on a column.
- Except NOT NULL constraint, UNIQUE, CHECK and FOREIGN KEY allow NULL values in to column. To restrict them you can explicitly impose a NOT NULL constraint on those columns.
CREATE Table BANK (CustomerId Int Primary Key, Cname Varchar (50), Balance Decimal (7,2) NOT NULL Constraint Bal_Chk CHECK (Balance >=1000)
No comments:
Post a Comment