hi. I need to create a table, but I want to set three forgein key each one of different tables. Is that posible to do with oracle?

Dani AI

Generated

Short answer for : yes. is correct and is also right that this is a general RDBMS capability — Oracle fully supports a single table having several foreign keys that reference different parent tables. Each foreign key must reference a PRIMARY KEY or UNIQUE key in the parent table, and the referenced columns should have compatible datatypes.

Example table definition (three FKs to different tables):

CREATE TABLE child_table (
  child_id       NUMBER PRIMARY KEY,
  parent_a_id    NUMBER,
  parent_b_id    NUMBER,
  parent_c_id    NUMBER,
  CONSTRAINT fk_child_parent_a FOREIGN KEY (parent_a_id)
    REFERENCES parent_a(id),
  CONSTRAINT fk_child_parent_b FOREIGN KEY (parent_b_id)
    REFERENCES parent_b(id),
  CONSTRAINT fk_child_parent_c FOREIGN KEY (parent_c_id)
    REFERENCES parent_c(id)
);

Practical tips and cautions: name each constraint (names must be unique in the schema) and verify datatypes match. Oracle does not automatically index foreign key columns, so add indexes on child FK columns if parent-row deletes/updates are common (this avoids full table scans/locking). Foreign-key columns may be NULL; NULLs bypass the check (composite FKs behave the same). To add a FK later use ALTER TABLE ... ADD CONSTRAINT .... For large datasets consider DEFERRABLE/INITIALLY options or NOVALIDATE when appropriate. Use ON DELETE CASCADE only after confirming the business rule, since it will remove child rows when the parent is deleted.

Recommended Answers

All 2 Replies

Yes.

Just a little bit more explanation.....
YES, IT IS POSSIBLE, BUT ITS NOT ORACLE FEATURE, ITS RDBMS FEATURE.All the dbms software which support relational database system, support this feature as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.