flask sql外鍵使用
Basically, Foreign Key represents relationship between tables.
基本上, 外鍵代表表之間的關系 。
Syntax:
句法:
column-name data_type (size) CONSTRAINT constraint-name
References Table-name (Column-name)
Example:
例:
Table 1:
表格1:
Table 2:
表2:

First create a primary key in first table which is also called unique key.
首先在第一個表中創建一個主鍵,也稱為唯一鍵。
Like this:
像這樣:
create table student
(enroll number(6) primary key, s_name varchar(25), address varchar2(20),
contact number(10) );
Second create foreign key by using second table.
第二個通過使用第二個表創建外鍵。
Like this:
像這樣:
create table student_fees
(enroll number(6) constraint en_fk References Student (enroll) , course_fee number(8),
status varchar2(6), amount number(10) );
Query to find student name, address, contact from the database.
查詢以從數據庫中找到學生的姓名,地址和聯系方式。
Conclusion:
結論:
In this article, we have learnt how to use foreign key and how it works and useful for us to retrieve data from the relational database? I hope you understand the concept; if you have any query, feel free to ask in the comment section.
在本文中,我們學習了如何使用外鍵以及它如何工作以及對我們從關系數據庫中檢索數據有用嗎? 希望您理解這個概念; 如果您有任何疑問,請隨時在評論部分提問。
翻譯自: https://www.includehelp.com/sql/how-to-use-foreign-key-in-sql.aspx
flask sql外鍵使用