TheCHECKconstraint is used in SQL toenforce ruleson a column's values. It ensures that data inserted into a table meets specified conditions, such as range restrictions or logical rules.
Example Usage:
sql
CREATE TABLE Employees (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Salary INT CHECK (Salary BETWEEN 30000 AND 150000)
);
This constraint ensures thatsalary values fall between 30,000 and 150,000.
If an INSERT or UPDATE statement tries to set Salary = 20000, itfailsbecause it does notmeet the CHECK condition.
Why Other Options Are Incorrect:
Option B (FROM) (Incorrect):Used in SELECT statements, not for constraints.
Option C (WHERE) (Incorrect):Filters rows in queries butdoes not enforce constraints.
Option D (SET) (Incorrect):Used for updating records (UPDATE table_name SET column = value) butnot for defining constraints.
Thus,CHECK is the correct answer, as it ensures that column values remain within an expected range.
[Reference:SQL Constraints and Data Validation​., ]
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit