Subject | Re: [ib-support] Re: another Error |
---|---|
Author | Lucas Franzen |
Post date | 2001-07-27T11:00:43Z |
Bernhard,
Bernhard Doebler schrieb:
1. you should use INTEGERS not SMALLINTS for Primary keys
2. it's no good idea to have a field referencing a table where the field
has got the same name as the table it is referencing (might be the
solution to your problem).
3. you don't have to declare NO ACTION, this is default
4. you shouldn't default a primary key
5. if you don't want to mess around with INTEG_95 (and browsing the
system tables to find out which relation this is) you can name the
primary key like:
Create table SCHICHT (
SCHICHTID Smallint Default 0 NOT NULL,
BEZEICHNUNG Varchar(20) NOT NULL,
CONSTRAINT PK_SCHICHT Primary Key (SCHICHTID)
);
Maybe it's a good idea to have a table identifier in front of your field
names so that you can always distinguish between tables and fields and
you do see where they belong to (or what they're referencing) like:
Create table SCHICHT (
SCHICHT_ID INTEGER NOT NULL,
SCHICHT_BEZEICHNUNG Varchar(20) NOT NULL,
CONSTRAINT PK_SCHICHT Primary Key (SCHICHTID)
) ;
CREATE TABLE DATEN (
DATEN_NUMMER INTEGER NOT NULL,
SCHICHT_ID INTEGER,
PRIMARY KEY PK_DATEN PRIMARY KEY ( DATEN_NUMMER )
);
ALTER TABLE DATEN DATEN ADD CONSTRAINT
FK_SCHICHTDATEN FOREIGN KEY ( SCHICHT_ID )
REFERENCES SCHICHT ON DELETE CASCADE;
HTH
Luc.
Bernhard Doebler schrieb:
>Just some thoughts:
> Hi.
>
> I meanwhile found out INTEG_95 is the PRIMARY KEY of table SCHICHT.
>
> But how can the error occur?
1. you should use INTEGERS not SMALLINTS for Primary keys
2. it's no good idea to have a field referencing a table where the field
has got the same name as the table it is referencing (might be the
solution to your problem).
3. you don't have to declare NO ACTION, this is default
4. you shouldn't default a primary key
5. if you don't want to mess around with INTEG_95 (and browsing the
system tables to find out which relation this is) you can name the
primary key like:
Create table SCHICHT (
SCHICHTID Smallint Default 0 NOT NULL,
BEZEICHNUNG Varchar(20) NOT NULL,
CONSTRAINT PK_SCHICHT Primary Key (SCHICHTID)
);
Maybe it's a good idea to have a table identifier in front of your field
names so that you can always distinguish between tables and fields and
you do see where they belong to (or what they're referencing) like:
Create table SCHICHT (
SCHICHT_ID INTEGER NOT NULL,
SCHICHT_BEZEICHNUNG Varchar(20) NOT NULL,
CONSTRAINT PK_SCHICHT Primary Key (SCHICHTID)
) ;
CREATE TABLE DATEN (
DATEN_NUMMER INTEGER NOT NULL,
SCHICHT_ID INTEGER,
PRIMARY KEY PK_DATEN PRIMARY KEY ( DATEN_NUMMER )
);
ALTER TABLE DATEN DATEN ADD CONSTRAINT
FK_SCHICHTDATEN FOREIGN KEY ( SCHICHT_ID )
REFERENCES SCHICHT ON DELETE CASCADE;
HTH
Luc.
> Alter table DATEN add foreign key (SCHICHT) references SCHICHT (SCHICHTID) on update no action on delete cascade;
>
> Best Regards
> Bernhard
>
> ----- Original Message -----
> From: "Bernhard Doebler" <programmer@...>
> To: <ib-support@yahoogroups.com>
> Sent: Friday, July 27, 2001 11:16 AM
> Subject: another Error
>
> my IBConsole says:
>
> Violation of FOREIGN KEY constraint "INTEG_95" on table "SCHICHT"
> Statement: Alter table DATEN add foreign key (SCHICHT) references SCHICHT (SCHICHTID) on update no action on delete cascade
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/