====== pears.DocumentTypeDepartment ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Description =====
Links Document Types to Departments. Types with no record are available for all Departments.
===== Columns =====
^ Column ^ Type ^ Null ^ Default ^ Comment ^
| **DocumentTypeDepartmentID** | char(20) | NOT NULL | | |
| DocumentTypeID | char(20) | NULL | | |
| DepartmentID | char(2) | NULL | | |
===== Primary Key =====
* DocumentTypeDepartmentID
===== Foreign Keys =====
^ Constraint ^ Columns ^ References ^ Delete/update action ^
| DocumentType | DocumentTypeID | [[database:tables:pears_documenttype|pears.DocumentType (DocumentTypeID)]] | ON DELETE CASCADE |
| Department | DepartmentID | [[database:tables:pears_department|pears.Department (departmentid)]] | ON DELETE CASCADE |
===== Referenced By =====
* No incoming foreign keys found.
===== Indexes =====
* No indexes found.
===== Triggers =====
^ Name ^ Timing ^ Event ^
| DocumentTypeDepartmentDelete | after | delete order 1 |
===== Original SQL =====
-- IQX database structure split by table
-- Source: IQXDatabaseStructure - with comments.sql
-- Table: "pears"."DocumentTypeDepartment"
-- Table comment: Links Document Types to Departments. Types with no record are available for all Departments.
-- Statement count: 6
CREATE TABLE "pears"."DocumentTypeDepartment" (
"DocumentTypeDepartmentID" char(20) NOT NULL
,"DocumentTypeID" char(20) NULL
,"DepartmentID" char(2) NULL
,PRIMARY KEY ("DocumentTypeDepartmentID" ASC)
)
go
COMMENT ON TABLE "pears"."DocumentTypeDepartment" IS
'Links Document Types to Departments. Types with no record are available for all Departments.'
go
ALTER TABLE "pears"."DocumentTypeDepartment"
ADD FOREIGN KEY "DocumentType" ("DocumentTypeID" ASC)
REFERENCES "pears"."DocumentType" ("DocumentTypeID")
ON DELETE CASCADE
go
ALTER TABLE "pears"."DocumentTypeDepartment"
ADD FOREIGN KEY "Department" ("DepartmentID" ASC)
REFERENCES "pears"."Department" ("departmentid")
ON DELETE CASCADE
go
create trigger "DocumentTypeDepartmentDelete" after delete order 1 on
"pears"."DocumentTypeDepartment"
referencing old as "OldTable"
for each row
begin
delete from "DocumentTag" where "DocumentTypeID" = "OldTable"."DocumentTypeID" and "TagLocation" = "string"('A',"OldTable"."DepartmentID")
end
go
COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."DocumentTypeDepartment"."DocumentTypeDepartmentDelete" IS
{create trigger DocumentTypeDepartmentDelete
after delete order 1 on
pears.DocumentTypeDepartment
referencing old as OldTable
for each row
begin
delete from DocumentTag where DocumentTypeID = OldTable.DocumentTypeID and TagLocation = string('A',OldTable.DepartmentID)
end
}
go