Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
angproj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Roman Weiss
angproj
Commits
cfd5a042
Commit
cfd5a042
authored
6 years ago
by
Raphael Das Gupta
Browse files
Options
Downloads
Patches
Plain Diff
move constraints tests to separate script file
parent
9cdc9eba
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
0_runAllScripts.sql
+3
-0
3 additions, 0 deletions
0_runAllScripts.sql
5_queries.sql
+0
-32
0 additions, 32 deletions
5_queries.sql
6_constraints_tests.sql
+29
-0
29 additions, 0 deletions
6_constraints_tests.sql
with
32 additions
and
32 deletions
0_runAllScripts.sql
+
3
−
0
View file @
cfd5a042
...
...
@@ -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
This diff is collapsed.
Click to expand it.
5_queries.sql
+
0
−
32
View file @
cfd5a042
...
...
@@ -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
;
$$
;
This diff is collapsed.
Click to expand it.
6_constraints_tests.sql
0 → 100644
+
29
−
0
View file @
cfd5a042
-- 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
;
$$
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment