Autor Beitrag
raiha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152



BeitragVerfasst: Mi 18.05.05 11:26 
Hi,

wie muss ich eine Tabelle mit FireBird anlegen damit ich als eindeutige ID soetwas wie AutoWert bei Access bekomme.

Ich will dann später nur noch Werte ohne die ID über Insert in die DB reinfüttern.

Geht das über Generatoren und wenn ja wie? Wie binde ich den an die Tabelle und wie muss ich den Trigger schreiben das er mir automatisch (before insert) die ID setzt.

Danke Rainer
OlliWausD
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 212

Win 2000/XP
Delphi 5 Professional - Interbase/Firebird
BeitragVerfasst: Mi 18.05.05 11:50 
du erstellst deine Tabelle ganz normal und anschließend:

ausblenden Quelltext
1:
CREATE GENERATOR GEN_Tabellenname_ID;					


ausblenden Quelltext
1:
2:
3:
'CREATE TRIGGER Triggername FOR Tabellenname '
+'ACTIVE BEFORE INSERT POSITION 0 AS BEGIN '
+'IF (NEW.ID IS NULL) THEN NEW.ID = GEN_ID(GEN_Tabellenname_ID,1); END';


Wenn du den IBExpert benutzt, kannst du das direkt durch nen einfachen Mausklick machen :)

www.ibexpert.com --> Free for Personal

mfg

Olli W

_________________
Take it easy
raiha Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152



BeitragVerfasst: Mi 18.05.05 12:13 
habe einen Generator namens AW angelegt

jetzt der Trigger

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
CREATE TRIGGER AW_SUM FOR SUM ACTIVE
BEFORE INSERT POSITION 0
AS
BEGIN
     IF (NEW.Nr IS NULL) THEN Nr.ID = GEN_ID(AW,1);
END


da bringt die Console aber folgenden Fehler

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
ISC ERROR CODE:335544569

ISC ERROR MESSAGE:
Dynamic SQL Error
SQL error code = -104
Unexpected end of command


Woran könnte das liegen ?
raiha Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152



BeitragVerfasst: Mi 18.05.05 12:26 
hatte mich verschrieben - meinte:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
CREATE TRIGGER AW_SUMMARY FOR SUMMARY ACTIVE
BEFORE INSERT POSITION 0
AS
BEGIN
     IF (NEW.Nr IS NULL) THEN NEW.Nr = GEN_ID(AW,1);
END
raiha Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152



BeitragVerfasst: Mi 18.05.05 13:20 
habe es jetzt auch mit dem ibexpert gemacht und es funktioniert

Danke für den Tipp

Rainer
OlliWausD
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 212

Win 2000/XP
Delphi 5 Professional - Interbase/Firebird
BeitragVerfasst: Fr 20.05.05 14:54 
kein Thema.

Des Tool is echt geil. Die Beste Investition, die mein Chef je gemacht hat :)

mfg

Olli W

_________________
Take it easy