我正在使用 D2K9、Zeos 7Alpha 和 Firebird 2.1
在添加 autoinc 字段之前,我已经完成了这项工作。虽然我不确定我做的是否 100% 正确。我不知道使用触发器、生成器等执行 SQL 代码的顺序。我尝试了几种组合,我猜我做错了什么,而不仅仅是因为这不起作用。
当前演示:http: //uploading.com/files/bd64d8m9/createdb.zip/
当前错误:
It's getting an error here:
SQL Error: Dynamic SQL Error SQL error code = -104 Token unknown - line 2, column 1 SET.
Error Code: -104. Invalid token The SQL:
CREATE GENERATOR GEN_EMAIL_ACCOUNTS_ID;
将 GENERATOR GEN_EMAIL_ACCOUNTS_ID 设置为 1;
来自 IBExpert 的 SQL 文件:
/******************************************************************************/
/* Generated by IBExpert 5/4/2010 3:59:48 PM */
/******************************************************************************/
/******************************************************************************/
/* Following SET SQL DIALECT is just for the Database Comparer */
/******************************************************************************/
SET SQL DIALECT 3;
/******************************************************************************/
/* Tables */
/******************************************************************************/
CREATE GENERATOR GEN_EMAIL_ACCOUNTS_ID;
CREATE TABLE EMAIL_ACCOUNTS (
ID INTEGER NOT NULL,
FNAME VARCHAR(35),
LNAME VARCHAR(35),
ADDRESS VARCHAR(100),
CITY VARCHAR(35),
STATE VARCHAR(35),
ZIPCODE VARCHAR(20),
BDAY DATE,
PHONE VARCHAR(20),
UNAME VARCHAR(255),
PASS VARCHAR(20),
EMAIL VARCHAR(255),
CREATEDDATE DATE,
"ACTIVE" BOOLEAN DEFAULT 0 NOT NULL /* BOOLEAN = SMALLINT CHECK (value is null or value in (0, 1)) */,
BANNED BOOLEAN DEFAULT 0 NOT NULL /* BOOLEAN = SMALLINT CHECK (value is null or value in (0, 1)) */,
"PUBLIC" BOOLEAN DEFAULT 0 NOT NULL /* BOOLEAN = SMALLINT CHECK (value is null or value in (0, 1)) */,
NOTES BLOB SUB_TYPE 0 SEGMENT SIZE 1024
);
/******************************************************************************/
/* Primary Keys */
/******************************************************************************/
ALTER TABLE EMAIL_ACCOUNTS ADD PRIMARY KEY (ID);
/******************************************************************************/
/* Triggers */
/******************************************************************************/
SET TERM ^ ;
/******************************************************************************/
/* Triggers for tables */
/******************************************************************************/
/* Trigger: EMAIL_ACCOUNTS_BI */
CREATE OR ALTER TRIGGER EMAIL_ACCOUNTS_BI FOR EMAIL_ACCOUNTS
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(GEN_EMAIL_ACCOUNTS_ID,1);
END
^
SET TERM ; ^
/******************************************************************************/
/* Privileges */
/******************************************************************************/
触发器:
/******************************************************************************/
/* Following SET SQL DIALECT is just for the Database Comparer */
/******************************************************************************/
SET SQL DIALECT 3;
CREATE GENERATOR GEN_EMAIL_ACCOUNTS_ID;
SET TERM ^ ;
CREATE OR ALTER TRIGGER EMAIL_ACCOUNTS_BI FOR EMAIL_ACCOUNTS
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(GEN_EMAIL_ACCOUNTS_ID,1);
END
^
SET TERM ; ^
发电机:
CREATE SEQUENCE GEN_EMAIL_ACCOUNTS_ID;
ALTER SEQUENCE GEN_EMAIL_ACCOUNTS_ID RESTART WITH 2;
/* Old syntax is:
CREATE GENERATOR GEN_EMAIL_ACCOUNTS_ID;
SET GENERATOR GEN_EMAIL_ACCOUNTS_ID TO 2;
*/
我的代码:在下面的评论中演示。