Oct 16, 2024
Creating a Table with Check Constraint:
employees).CHECK (hourly_pay >= 10)
CONSTRAINT keyword followed by a name (e.g., chk_hourly_pay).Adding Check Constraint to Existing Table:
ALTER TABLE statement.ALTER TABLE employees
ADD CONSTRAINT chk_hourly_pay CHECK (hourly_pay >= 10)
Inserting Data: Attempt to insert an employee with an hourly pay less than the constraint.
INSERT INTO employees VALUES (6, 'Sheldon', 'Plankton', 5, '2023-01-07')
check hourly pay constraint, hence insertion fails.Successful Insertion: Adjust to meet constraint:
$10 and reinsert.ALTER TABLE employees
DROP CONSTRAINT chk_hourly_pay