哪个表应该是父表,哪个应该是子表? [英] Which table should be Parent table and which should be child table?

查看:152
本文介绍了哪个表应该是父表,哪个应该是子表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨有两个表Auther和书。
我很困惑我应该保留哪个表作为父表,哪个表应该是用于制作外键约束的子表。

  CREATE TABLE author 

author_id NUMBER(3)CONSTRAINT athr_aid_pk PRIMARY KEY,
author_name VARCHAR2(30)
);

CREATE TABLE books

book_id NUMBER(3),
book_title VARCHAR2(30),
book_price NUMBER(3),

);

请告诉我哪个表应该是父表,为什么?



原因: >这是一个多对多关系。



解决方案:创建一个单独的表,包含两个列author_id,book_id都是外键。


Hi have two tables Auther and Books. I am confused that to which table should i keep as parent table and which should be child table for making foreign key constraint.

CREATE TABLE author
 (
    author_id NUMBER(3) CONSTRAINT athr_aid_pk PRIMARY KEY,
    author_name VARCHAR2(30)
 );

 CREATE TABLE books
 (
    book_id NUMBER(3),
    book_title VARCHAR2(30),
    book_price NUMBER(3),

 );

Please explain me which table should be Parent table and why?

解决方案

Answer: None.

Reason: This is a many-to-many relationship. An author can have any number of books written, also a book can have more than one author.

Solution: Make a separate table with two columns author_id, book_id both are foreign keys.

这篇关于哪个表应该是父表,哪个应该是子表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆