-- IQX database structure split by table
-- Source: IQXDatabaseStructure - with comments.sql
-- Table: "pears"."SalesBrand"
-- Table comment:
-- Statement count: 8
CREATE TABLE "pears"."SalesBrand" (
"SalesBrandID" CHAR(20) NOT NULL
,"DivisionID" CHAR(20) NULL
,"InvoicePrefix" CHAR(10) NULL
,"Description" CHAR(50) NOT NULL
,"Analysis" CHAR(50) NULL
,"AlternativeInvoiceAddressEmailID" CHAR(20) NULL
,"InvoiceEmail" CHAR(250) NULL
,"InvoiceAddress" long VARCHAR NULL
,"Defunct" tinyint NOT NULL DEFAULT 0
,PRIMARY KEY ("SalesBrandID" ASC)
)
GO
COMMENT ON COLUMN "pears"."SalesBrand"."AlternativeInvoiceAddressEmailID" IS
'may not be used'
GO
COMMENT ON COLUMN "pears"."SalesBrand"."InvoiceEmail" IS
'may not be used'
GO
COMMENT ON COLUMN "pears"."SalesBrand"."InvoiceAddress" IS
'may not be used'
GO
ALTER TABLE "pears"."SalesBrand"
ADD FOREIGN KEY "Division" ("DivisionID" ASC)
REFERENCES "pears"."Division" ("divisionid")
ON DELETE CASCADE
GO
ALTER TABLE "pears"."SalesBrand"
ADD FOREIGN KEY "AlternativeInvoiceAddressEmail" ("AlternativeInvoiceAddressEmailID" ASC)
REFERENCES "pears"."AlternativeInvoiceAddressEmail" ("AlternativeInvoiceAddressEmailID")
ON DELETE CASCADE
GO
CREATE TRIGGER "SalesBrandAudit" after UPDATE OF "InvoiceEmail",
"InvoiceAddress","InvoicePrefix" ORDER 1 ON
"pears"."SalesBrand"
REFERENCING OLD AS "old_brand" NEW AS "new_brand"
FOR each ROW
BEGIN
IF UPDATE("InvoiceEmail") THEN
CALL "AuditLog"('SALESBRAND',"new_brand"."SalesBrandID","string"("new_brand"."description",' - Email'),"old_brand"."InvoiceEmail","new_brand"."InvoiceEmail")
ELSE IF UPDATE("InvoiceAddress") THEN
CALL "AuditLog"('SALESBRAND',"new_brand"."SalesBrandID","string"("new_brand"."description",' - Address'),"old_brand"."InvoiceAddress","new_brand"."InvoiceAddress")
ELSE IF UPDATE("InvoicePrefix") THEN
CALL "AuditLog"('SALESBRAND',"new_brand"."SalesBrandID","string"("new_brand"."description",' - Prefix'),"old_brand"."InvoicePrefix","new_brand"."InvoicePrefix")
END IF END IF END IF
END
GO
COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."SalesBrand"."SalesBrandAudit" IS
{CREATE TRIGGER SalesBrandAudit
after UPDATE OF InvoiceEmail,InvoiceAddress,InvoicePrefix ORDER 1 ON
SalesBrand
REFERENCING OLD AS old_brand NEW AS new_brand
FOR each ROW
BEGIN
IF UPDATE (InvoiceEmail) THEN
CALL AuditLog('SALESBRAND',new_brand.SalesBrandID,string(new_brand.description ,' - Email'),old_brand.InvoiceEmail,new_brand.InvoiceEmail)
ELSE IF UPDATE (InvoiceAddress) THEN
CALL AuditLog('SALESBRAND',new_brand.SalesBrandID,string(new_brand.description ,' - Address'),old_brand.InvoiceAddress,new_brand.InvoiceAddress)
ELSE IF UPDATE (InvoicePrefix) THEN
CALL AuditLog('SALESBRAND',new_brand.SalesBrandID,string(new_brand.description ,' - Prefix'),old_brand.InvoicePrefix,new_brand.InvoicePrefix)
END IF END IF END IF;
END
}
GO