🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.bazy-danych
2 messages
2 total messages Started by Borneq Thu, 20 Aug 2015 13:28
Jak kasowanie rekordu ma wymusić skasowanie odniesienia?
#194572
Author: Borneq
Date: Thu, 20 Aug 2015 13:28
24 lines
1674 bytes
Mam
CREATE GENERATOR GEN_BOOKS_AUTHORS_ID;
CREATE GENERATOR GEN_BOOKS_AUTHORS_ID;

CREATE TABLE BOOKS (
     ID_BOOKS        INTEGER NOT NULL,
     TITLE           VARCHAR(60) CHARACTER SET UTF8 NOT NULL,
);

CREATE TABLE BOOKS_AUTHORS (
     ID_BOOKS_AUTHORS  INTEGER NOT NULL,
     ID_BOOKS          INTEGER NOT NULL,
);

ALTER TABLE BOOKS ADD PRIMARY KEY (ID_BOOKS);
ALTER TABLE BOOKS_AUTHORS ADD PRIMARY KEY (ID_BOOKS_AUTHORS);
ALTER TABLE BOOKS_AUTHORS ADD CONSTRAINT FK_BOOKS_AUTHORS_1 FOREIGN KEY 
(ID_BOOKS) REFERENCES BOOKS (ID_BOOKS);

Chcę skasować dane tabel zachowując ich strukturę. Kasuję po kolei 
tabele, najpierw BOOKS, ale nie mogę bo odnosi się do niej rekord z 
tabeli BOOKS_AUTHORS.
Jak zrobić aby kasowanie rekordu skasowało rekord odniesienia?
Baza Firebird.
Re: Jak kasowanie rekordu ma wymusić skasowanie odniesienia?
#194573
Author: Lesiok
Date: Thu, 20 Aug 2015 13:38
31 lines
1964 bytes
W dniu 2015-08-20 o 15:28, Borneq pisze:
> Mam
> CREATE GENERATOR GEN_BOOKS_AUTHORS_ID;
> CREATE GENERATOR GEN_BOOKS_AUTHORS_ID;
>
> CREATE TABLE BOOKS (
>      ID_BOOKS        INTEGER NOT NULL,
>      TITLE           VARCHAR(60) CHARACTER SET UTF8 NOT NULL,
> );
>
> CREATE TABLE BOOKS_AUTHORS (
>      ID_BOOKS_AUTHORS  INTEGER NOT NULL,
>      ID_BOOKS          INTEGER NOT NULL,
> );
>
> ALTER TABLE BOOKS ADD PRIMARY KEY (ID_BOOKS);
> ALTER TABLE BOOKS_AUTHORS ADD PRIMARY KEY (ID_BOOKS_AUTHORS);
> ALTER TABLE BOOKS_AUTHORS ADD CONSTRAINT FK_BOOKS_AUTHORS_1 FOREIGN KEY
> (ID_BOOKS) REFERENCES BOOKS (ID_BOOKS);
>
> Chcę skasować dane tabel zachowując ich strukturę. Kasuję po kolei
> tabele, najpierw BOOKS, ale nie mogę bo odnosi się do niej rekord z
> tabeli BOOKS_AUTHORS.
> Jak zrobić aby kasowanie rekordu skasowało rekord odniesienia?
> Baza Firebird.

Klucz FOREIGN KEY musi mieć w definicji dodane ON DELETE CASCADE.

-- 
Pozdrawiam,
Leszek Kubrak
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads