DibaToner DibaToner - 2 months ago 17
SQL Question

create sql Database from ER diagram

ER-Diagram

I tried to make Kann table like this:

CREATE TABLE Kann(
id integer NOT NULL PRIMARY KEY,
MiNr integer REFERENCES Employer(MiNr),
FNr integer REFERENCES Ability(FNr)
);


The problem is that I want Oracle to automatically insert data in
Kann
and
Cooperation
tables, when I insert data manually in
Ability
,
Employer
and
Project
tables.

How is that possible? Should I use triggers or other PL/SQL elements or I can do it only with SQL?

Answer

You can only build Diagram from existing code ER

You don`t need a triger or something else, just do relation between databases. The relationship between 2 tables matches the Primary Key in one of the tables with a Foreign Key in the second table.

Or just do Foreign Key in your database. A FOREIGN KEY in one table points to a PRIMARY KEY in another table.

CREATE TABLE Orders
(
O_Id int NOT NULL PRIMARY KEY,
OrderNo int NOT NULL,
P_Id int FOREIGN KEY REFERENCES Persons(P_Id)
)

Or if you alredy have a tables:

ALTER TABLE Orders
ADD FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id)
Comments