finki-main
main
|
Last change
on this file since 06ebe74 was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 2 weeks ago |
|
Project Handcraft Marketplace
|
-
Property mode
set to
100644
|
|
File size:
738 bytes
|
| Line | |
|---|
| 1 | CREATE OR REPLACE FUNCTION prevent_store_deletion()
|
|---|
| 2 | RETURNS TRIGGER
|
|---|
| 3 | LANGUAGE plpgsql
|
|---|
| 4 | AS $$
|
|---|
| 5 | BEGIN
|
|---|
| 6 | -- Check whether the store has existing reports
|
|---|
| 7 | IF EXISTS ( SELECT 1 FROM report WHERE store_id = OLD.store_id ) THEN
|
|---|
| 8 | RAISE EXCEPTION 'Store % cannot be deleted because it has existing reports.', OLD.store_id;
|
|---|
| 9 | END IF;
|
|---|
| 10 | -- Check whether the store has products associated with it
|
|---|
| 11 | IF EXISTS ( SELECT 1 FROM sells WHERE store_id = OLD.store_id ) THEN
|
|---|
| 12 | RAISE EXCEPTION 'Store % cannot be deleted because it has existing product records.', OLD.store_id;
|
|---|
| 13 | END IF;
|
|---|
| 14 | RETURN OLD;
|
|---|
| 15 | END;
|
|---|
| 16 | $$;
|
|---|
| 17 |
|
|---|
| 18 | CREATE TRIGGER trg_prevent_store_deletion
|
|---|
| 19 | BEFORE DELETE
|
|---|
| 20 | ON store
|
|---|
| 21 | FOR EACH ROW
|
|---|
| 22 | EXECUTE FUNCTION prevent_store_deletion();
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.