If the value is appropriate:
If the value is not appropriate:
You create a check constraint at the time you are creating a
table.
To create a check constraint, create the
column on which the constraint will apply. Before the closing parenthesis of the table definition, use the
following formula:
CONSTRAINT name CHECK (expression)
The CONSTRAINT and the CHECK keywords are
required. As an object, make sure you provide a name for it. Inside the
parentheses that follow the CHECK operator, enter the expression that will be
applied. Here is an example that will make sure that the hourly salary specified
for an employee is greater than 12.50:
SQL> CREATE TABLE Employees
2 (
3 EmployeeNumber nchar(6),
4 FirstName nvarchar2(20),
5 LastName nvarchar2(20),
6 HourlySalary number(6, 2),
7 CONSTRAINT CHK_HourlySalary CHECK(HourlySalary > 12.50)
8 );
Table created.
SQL>
With the constraint(s) in place, during data entry, if the
user provides an invalid value, an error would display.
|
|
|||||||
|
Check Constraints
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment