Skip to content
Snippets Groups Projects
Commit cfd5a042 authored by Raphael Das Gupta's avatar Raphael Das Gupta
Browse files

move constraints tests to separate script file

parent 9cdc9eba
No related branches found
No related tags found
No related merge requests found
......@@ -60,3 +60,6 @@ CREATE DATABASE :database WITH OWNER :user ENCODING 'UTF8';
-- query the database
\ir 5_queries.sql
-- demonstrate constraints in action
\ir 6_constraints_tests.sql
......@@ -82,35 +82,3 @@ SELECT * FROM GutVerdienende;
-- forget all changes made since BEGIN
ROLLBACK;
-- Constraints Tests
-- do not alter contents of the database persistently
DO
$$BEGIN
ALTER TABLE Angestellter
ADD CONSTRAINT check_Salaer
CHECK (Salaer between 1000 and 20000);
UPDATE angestellter SET salaer=30000 where persnr = 1100;
select * from angestellter WHERE persnr = 1100;
-- forget all changes made since BEGIN
EXCEPTION
WHEN integrity_constraint_violation THEN
RAISE NOTICE 'The constraint worked and made the UPDATE fail with message: %', SQLERRM;
END;$$;
-- do not alter contents of the database persistently
DO
$$BEGIN
ALTER TABLE ProjektZuteilung
ADD CONSTRAINT check_Zeitanteil
CHECK (Zeitanteil between 10 and 90);
UPDATE ProjektZuteilung SET Zeitanteil=99 where persnr = 1100;
select * from ProjektZuteilung WHERE persnr = 1100;
-- forget all changes made since BEGIN
EXCEPTION
WHEN integrity_constraint_violation THEN
RAISE NOTICE 'The constraint worked and made the UPDATE fail with message: %', SQLERRM;
END;$$;
-- do not alter contents of the database persistently
DO
$$BEGIN
ALTER TABLE Angestellter
ADD CONSTRAINT check_Salaer
CHECK (Salaer between 1000 and 20000);
UPDATE angestellter SET salaer=30000 where persnr = 1100;
select * from angestellter WHERE persnr = 1100;
-- forget all changes made since BEGIN
EXCEPTION
WHEN integrity_constraint_violation THEN
RAISE NOTICE 'The constraint worked and made the UPDATE fail with message: %', SQLERRM;
END;$$;
-- do not alter contents of the database persistently
DO
$$BEGIN
ALTER TABLE ProjektZuteilung
ADD CONSTRAINT check_Zeitanteil
CHECK (Zeitanteil between 10 and 90);
UPDATE ProjektZuteilung SET Zeitanteil=99 where persnr = 1100;
select * from ProjektZuteilung WHERE persnr = 1100;
-- forget all changes made since BEGIN
EXCEPTION
WHEN integrity_constraint_violation THEN
RAISE NOTICE 'The constraint worked and made the UPDATE fail with message: %', SQLERRM;
END;$$;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment