PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 8th, 2003, 04:28 PM
pablo.gosse pablo.gosse is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 155 pablo.gosse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 6 m 5 sec
Reputation Power: 11
Ensuring a specific record NEVER gets deleted

Hi all. Quick question about triggers.

Is it possible to set up a trigger such that a specific record in a table NEVER can be deleted?

I'm writing a CMS and I want to set it up such that home pages cannot be deleted.

I guess it would be something like this:

CREATE TRIGGER is_home
BEFORE DELETE ON cms_pages FOR EACH ROW
EXECUTE PROCEDURE check_is_home(...params...);

The function will examine the row being deleted to see if the column is_home is set to 1 (true) or 0 (false) and then act accordingly.

Will doing this actually work? I haven't implemented any triggers on the database yet, I'm just going through everything now and seeing where I can clean up the code and this is one of the most important ones.

Any advice is greatly appreciated.

Thanks in advance,

Pablo

Reply With Quote
  #2  
Old July 9th, 2003, 12:49 PM
metaBarf metaBarf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 373 metaBarf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 49 m 6 sec
Reputation Power: 11
it'll work as long as that one record matches the criteria you specify in the procedure. However, if other records match the same criteria that you have specified then they will also be exempt from deletion. You could potentially add another attribute that is unique on records to fully specify the ones you wish to keep around through the use of the trigger.

ps. triggers are scary! they can have adverse effects if written incorrectly so be careful!!!

Reply With Quote
  #3  
Old July 9th, 2003, 12:59 PM
pablo.gosse pablo.gosse is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 155 pablo.gosse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 6 m 5 sec
Reputation Power: 11
Thanks for the tips.

I've actually created rules instead, which are much safer.

The records I wish to never be deleted are created when I create the database, so I can be certain that they will always be there, and the columns that I reference in the rules are primary keys, so there will never be more than one match.

Thanks again.

P.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Ensuring a specific record NEVER gets deleted

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap