Datenbank aufsetzen

  • Folgendes Script in der Eingabeaufvorderung mit isql ausführen:
  • SET SQL DIALECT 3;

    SET NAMES WIN1252;

    CREATE DATABASE 'c:\php_interbase_bsp.gdb'
    USER 'SYSDBA' PASSWORD 'masterkey'
    PAGE_SIZE 1024
    DEFAULT CHARACTER SET WIN1252;

    CREATE GENERATOR ID_KUNDE;
    SET GENERATOR ID_KUNDE TO 4;

    CREATE GENERATOR ID_BESTELLUNG;
    SET GENERATOR ID_BESTELLUNG TO 14;

    CREATE TABLE KUNDE (
    ID INTEGER NOT NULL,
    BEZ CHAR(64)
    );

    CREATE TABLE BESTELLUNG (
    ID INTEGER NOT NULL,
    ID_KUNDE INTEGER,
    SUMME INTEGER
    );

    INSERT INTO KUNDE (ID,BEZ) VALUES (1,'Morbitzer');
    INSERT INTO KUNDE (ID,BEZ) VALUES (2,'Kettl');
    INSERT INTO KUNDE (ID,BEZ) VALUES (3,'Meier');

    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (1,1,100);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (2,1,200);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (3,1,300);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (4,2,100);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (5,2,200);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (6,2,300);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (7,2,400);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (8,3,100);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (9,3,200);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (10,3,300);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (11,3,400);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (12,3,500);
    INSERT INTO BESTELLUNG (ID,ID_KUNDE,SUMME) VALUES (13,3,600);

    ALTER TABLE BESTELLUNG ADD CONSTRAINT PK_BESTELLUNG PRIMARY KEY (ID);
    ALTER TABLE KUNDE ADD CONSTRAINT PK_KUNDE PRIMARY KEY (ID);

    CREATE INDEX KEY_ID_KUNDE ON BESTELLUNG (ID_KUNDE);

    SET TERM ^ ;

    CREATE TRIGGER KUNDE_BI0 FOR KUNDE
    ACTIVE BEFORE INSERT POSITION 0
    AS
    declare variable id integer;
    begin
    select gen_id(id_kunde,1) from rdb$database
    into :id;

    kunde.id=:id;
    end
    ^

    CREATE TRIGGER BESTELLUNG_BI0 FOR BESTELLUNG
    ACTIVE BEFORE INSERT POSITION 0
    AS
    declare variable id integer;
    begin
    select gen_id(id_bestellung,1) from rdb$database
    into :id;

    bestellung.id=:id;
    end
    ^

    SET TERM ; ^

    Script zum Downloaden: php_interbase_bsp.sql

    isql -i php_interbase_bsp.sql -u sysdba -p masterkey