اليوم بعد ان انهينا من انشاء الجداول نبدأ في انشاء بعض الاشياء المساعدة مثل :
(1 ) فهرس لجدول الاسعار
===============
create INDEX price_index on price (prodid,startdate ) ;
( 2) مسلسل اتوماتيكس لارقام الطلبيات
=======================
create SEQUENCE ORDID INCREMENT BY 1 start with 200 nocache ;
( 3 ) مسلسل لتوماتيكي لرقام السلع
=====================
create SEQUENCE proid increment by 1 start with 150 nocache ;
( 4 ) مسلسل اتوماتيكي لارقام العملاء
======================
create SEQUENCE custid increment by 1 start with 300 nocache ;
انتهينا الان من هذه الخطوات و نبدأ الان في انشاء ال triggers الخاصة بتلك الجداول
* اعداد trigger لضبط اختيا ر رقم الموظف المسجل في جدول العملاء حيث تكون وظيفته هي بائع
create or replace trigger check_repid
DECLARE
v_job varchar2 ( 30;
begin
select job into v_job from emp
where empno = : new.repid ;
if v_job != ' SALESMAN ' then
raise_application_error ( ' the repid is not a SALESMAN );
end if ;
exception
when_no_data_found then
raise_application_error ( ' the repid is not a EMPLOYEE' ) ;
end ;
* نقوم الان باعداد برنامج يمنع من التعديل في سجل الطلبية طالما انه قد تم شحنها و نستدل على ذلك من تاريخ الشحن
create or replace trigger shipped_already
declare
v_shipdate date;
begin
if inserting then select shipdate into v_shipdate from ord
where orid = : new.ordid ;
else
select shipdate into v_shipdate ord
where orid =:old.ordid
end if ;
if v_shipdate is not null then
raise_application_error ( ' order has been shipped already ') ;
end if ;
end ;
* نعد الان برنامج للتاكد من ان تاريخ شحن الطلبية ليس قبل تاريخ تقديم الطلبية
create or replace trigger ship_ord_date
before update of shipdate on ord
for each row
begin
if :old.orddate > : new.shipdate
then
raise_application_error ( 'cannot have a ship date before the order date ) ;
end if ;
end ;
* نعد الان برنامج للتاكد من السعر الادنى للسلعة لا يزيد عن السعر الاساسي
create or replace trigger cheek_price
berfor insert or update of minprice on price for each row
begin
if : new.minprice > :new.stdprice then
raise_application_error ( ' standard price must be more than minimum price ) ;
end if ;
end ;
في المرة القادمة باذن الله نبدأ معا في انشاء ال forms
و اعتذر عن عدم استطاعتي الايطال هذه المرة بسبب وجود بعض الاعمال الذي لابد الانتهاء منها