打开Office Base:如何创建INSERT触发器

时间:2014-08-11 20:43:26

标签: sql openoffice.org openoffice-base

我正在使用OpenOffice Base和一些自制的sql创建数据库。当尝试引用数字和可能是字母的外键时出现问题。我想强制表我正在检查密钥以强制插入大写(或更低,我不挑剔)并对正在进行检查的表执行相同操作。表格:

DROP TABLE IF EXISTS Gun;
DROP TABLE IF EXISTS Model;  
DROP TABLE IF EXISTS Value;

CREATE TABLE Model (
    "Model Name" VARCHAR (25) NOT NULL PRIMARY KEY,
    "Manufacuture" VARCHAR (15) NOT NULL,
    "Manufactured Start Year" INTEGER NOT NULL,
    "Manufactured End Year" INTEGER,
    "Gun Type" VARCHAR (10),
    "Value Mininum" DECIMAL (10, 2),
    "Value Maximum" DECIMAL (10, 2) NOT NULL,
    "Description" VARCHAR (500)
);

CREATE TABLE Gun (
    "Serial Number" VARCHAR (25) NOT NULL,
    "Model Name" VARCHAR (25),
    "Caliber" VARCHAR (10),
    "Unique Features" VARCHAR (200),
    "Manufactured Date" INTEGER,
    "Condition" INTEGER,
    CONSTRAINT FK_MODEL FOREIGN KEY ("Model Name") REFERENCES Model ("Model Name"),
    CONSTRAINT PK_GUN_KEY PRIMARY KEY ("Serial Number", "Model Name"),
    CONSTRAINT CK_CONDITION CHECK( "Condition" <= 100 )    
);

触发器(不起作用,是我尝试过的许多之一):

CREATE TRIGGER ForceUpper BEFORE INSERT ON Model
SET Model."Model Name" = UPPER(Model."Model Name");

给出了:

Unexpected end of command: SET in statement

关于我做错的任何提示都会很好。我看到的HyperSQL文档除了添加BEGIN ATOMIC之外几乎没什么帮助,BEGIN ATOMIC也有意想不到的结束命令(即使是END)。感谢

1 个答案:

答案 0 :(得分:0)

检查HSQLDB documentation,我认为你的语法应该是:

create trigger ForceUpper before insert on Model
    for each row set new."Model Name" = UPPER(new."Model Name")

new关键字指的是正在插入的新行

注意:我建议您避免在表名和/或列名中使用空格。如果您需要分隔单词,请使用_代替空格或使用CamelCase