🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.databases.mssql-l
Article #17

Re: Database triggers

#17
From: Charity M
Date: Fri, 16 Apr 2004 12:32
75 lines
3086 bytes
Thank you, will look at the reference manual.  This is how I've done
it to this point.  It runs and the trigger is created but am not quite
sure if its the right thing.

CREATE OR REPLACE TRIGGER QUOTE_TRG
BEFORE INSERT or DELETE OR UPDATE ON QUOTE
FOR EACH ROW
DECLARE
	today_date date;
	part_cost number(8, 2);
	current_status char(1);
	future_date exception;
	high_cost exception;
	discount_error exception;
	invalid_insert exception;
	invalid_status exception;
	delete_status exception;

BEGIN
if inserting or updating then
	today_date := :new.QUOTE_DATE;
	if today_date > SYSDATE then
		raise future_date;
	end if;
	select PART.UNIT_COST into part_cost from PART where PART.PART_NBR =
:NEW.PART;
	if part_cost < :NEW.UNIT_COST then
		raise high_cost;
	end if;

	if :NEW.QUANTITY > 100 then
		if (part_cost * .8) < :NEW.UNIT_COST then
			raise discount_error;
		end if;
	end if;
end if;
if inserting then
	if upper(:NEW.STATUS) != 'P' then
		raise invalid_insert;
	end if;
end if;
if updating then
	if upper(:NEW.STATUS) != 'A' then
		raise invalid_status;
	end if;
end if;
if deleting then
	select QUOTE.STATUS into current_status from QUOTE where QUOTE.ID =
:NEW.ID;
	if current_status != 'P' and current_status != 'C' then
		raise delete_status;
	end if;
end if;

EXCEPTION
	when future_date then
		raise_application_error(-20110, 'Quote date cannot be a future
date.');
	when high_cost then
		raise_application_error(-20111, 'Quoted price is too high');
	when discount_error then
		raise_application_error(-20112, 'Quoted discount price is too
high');
	when invalid_insert then
		raise_application_error(-20113, 'New quotes must have a status of
P');
	when invalid_status then
		raise_application_error(-20114, 'Pending status (P) con only be
changed to Approved (A)');
	when delete_status then
		raise_application_error(-20115, 'Status must be (P) Pending or (C)
Cancelled to be deleted');


END;
Technical Details
Message-ID: <2590fb58.0404160432.1691ebce@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
References: <2590fb58.0404140557.71480015@posting.google.com> <MPG.1ae85cb4749764d29896d8@news.easynews.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1077ec,22e47e48c1055942
X-Google-Attributes: gid1077ec,public
X-Google-Thread: f6611,22e47e48c1055942
X-Google-Attributes: gidf6611,public
X-Google-Thread: 10c397,22e47e48c1055942
X-Google-Attributes: gid10c397,public
X-Google-ArrivalTime: 2004-04-16 05:32:58 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
From: cmpofu@iupui.edu (Charity M)
Newsgroups: bit.databases.mssql-l,comp.databases.postgresql.sql,comp.sys.ibm.as400.misc
Subject: Re: Database triggers
Date: 16 Apr 2004 05:32:57 -0700
Organization: http://groups.google.com
Lines: 75
Message-ID: <2590fb58.0404160432.1691ebce@posting.google.com>
References: <2590fb58.0404140557.71480015@posting.google.com> <MPG.1ae85cb4749764d29896d8@news.easynews.com>
NNTP-Posting-Host: 205.144.127.200
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1082118778 13116 127.0.0.1 (16 Apr 2004 12:32:58 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 16 Apr 2004 12:32:58 +0000 (UTC)