stefanuddenberg
3/2/2020 - 2:52 AM

SQL -- Check constraints

-- Use CONSTRAINT keyword to name the check yourself
CREATE TABLE new_user(
	id serial PRIMARY KEY,
	first_name VARCHAR(50) NOT NULL,
	birth_date DATE CHECK(birth_date > '1900-01-01'),
	join_date DATE CONSTRAINT joined_after_born CHECK(join_date > birth_date),
	salary INTEGER CHECK(salary > 0)
);

INSERT INTO new_user(
	first_name, 
	birth_date,
	join_date,
	salary
)
VALUES(
	'Bob',
	'1964-06-06',
	'2020-03-01',
	50000
)