Show pageOld revisionsBacklinksExport to PDFFold/unfold allBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== pears.DivisionAccess ====== <WRAP center round info> Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. </WRAP> ===== Description ===== Links Staff records to Divisions. Staff with no records have access to all Divisions. ===== Columns ===== ^ Column ^ Type ^ Null ^ Default ^ Comment ^ | **divisionid** | char(20) | NOT NULL | | | | **staffid** | char(20) | NOT NULL | | | ===== Primary Key ===== * divisionid, staffid ===== Foreign Keys ===== ^ Constraint ^ Columns ^ References ^ Delete/update action ^ | division | divisionid | [[database:tables:pears_division|pears.Division (divisionid)]] | NOT NULL; ON DELETE CASCADE | | staff | staffid | [[database:tables:pears_staff|pears.staff (staffid)]] | NOT NULL; ON DELETE CASCADE | ===== Referenced By ===== * No incoming foreign keys found. ===== Indexes ===== * No indexes found. ===== Triggers ===== ^ Name ^ Timing ^ Event ^ | WPK_divisionaccess_DIVISION | after | insert,delete,update order 1 | | DivisionAccessInsertAudit | after | insert order 1 | | DivisionAccessDeleteAudit | after | delete order 1 | ===== Original SQL ===== <code sql> -- IQX database structure split by table -- Source: IQXDatabaseStructure - with comments.sql -- Table: "pears"."DivisionAccess" -- Table comment: Links Staff records to Divisions. Staff with no records have access to all Divisions. -- Statement count: 10 CREATE TABLE "pears"."DivisionAccess" ( "divisionid" char(20) NOT NULL ,"staffid" char(20) NOT NULL ,PRIMARY KEY ("divisionid" ASC,"staffid" ASC) ) go COMMENT ON TABLE "pears"."DivisionAccess" IS 'Links Staff records to Divisions. Staff with no records have access to all Divisions.' go ALTER TABLE "pears"."DivisionAccess" ADD NOT NULL FOREIGN KEY "division" ("divisionid" ASC) REFERENCES "pears"."Division" ("divisionid") ON DELETE CASCADE go ALTER TABLE "pears"."DivisionAccess" ADD NOT NULL FOREIGN KEY "staff" ("staffid" ASC) REFERENCES "pears"."staff" ("staffid") ON DELETE CASCADE go create trigger "WPK_divisionaccess_DIVISION" after insert,delete,update order 1 on "pears"."divisionaccess" for each statement begin call "WPKTrackChange"('P','DIVISION') end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."DivisionAccess"."WPK_divisionaccess_DIVISION" IS {create trigger WPK_divisionaccess_DIVISION after insert,delete,update order 1 on divisionaccess for each statement begin call WPKTrackChange('P','DIVISION') end } go create trigger "DivisionAccessInsertAudit" after insert order 1 on "pears"."DivisionAccess" referencing new as "new_access" for each row when(exists(select * from "AuditItems" where "AreaName" = 'User' and "AuditFlag" = 1 and "ItemName" = 'Division Access')) begin declare "RoleName" char(50); declare "StaffName" char(25); select "name" into "RoleName" from "division" where "divisionid" = "new_access"."divisionid"; select "userid" into "StaffName" from "staff" where "staffid" = "new_access"."staffid"; call "AuditLog"('USER','',"string"("StaffName",' Added division ',"RoleName"),'','Added') end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."DivisionAccess"."DivisionAccessInsertAudit" IS {create trigger DivisionAccessInsertAudit after insert order 1 on DivisionAccess referencing new as new_access for each row when(exists(select * from AuditItems where AreaName = 'User' and AuditFlag = 1 and ItemName = 'Division Access')) begin declare RoleName char(50); declare StaffName char(25); select name into RoleName from division where divisionid = new_access.divisionid; select userid into StaffName from staff where staffid = new_access.staffid; call AuditLog('USER','',string(StaffName,' Added division ',RoleName),'','Added') end } go create trigger "DivisionAccessDeleteAudit" after delete order 1 on "pears"."DivisionAccess" referencing old as "old_access" for each row when(exists(select * from "AuditItems" where "AreaName" = 'User' and "AuditFlag" = 1 and "ItemName" = 'Division Access')) begin declare "RoleName" char(50); declare "StaffName" char(25); select "name" into "RoleName" from "division" where "divisionid" = "old_access"."divisionid"; select "userid" into "StaffName" from "staff" where "staffid" = "old_access"."staffid"; call "AuditLog"('USER','',"string"("StaffName",' Removed division ',"RoleName"),'Deleted','') end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."DivisionAccess"."DivisionAccessDeleteAudit" IS {create trigger DivisionAccessDeleteAudit after delete order 1 on DivisionAccess referencing old as old_access for each row when(exists(select * from AuditItems where AreaName = 'User' and AuditFlag = 1 and ItemName = 'Division Access')) begin declare RoleName char(50); declare StaffName char(25); select name into RoleName from division where divisionid = old_access.divisionid; select userid into StaffName from staff where staffid = old_access.staffid; call AuditLog('USER','',string(StaffName,' Removed division ',RoleName),'Deleted','') end } go </code> database/tables/pears_divisionaccess.txt Last modified: 2026/08/07 19:24by 127.0.0.1