flask sql外键使用_如何在SQL中使用外键?
flask sql外鍵使用
Basically, Foreign Key represents relationship between tables.
基本上, 外鍵代表表之間的關(guān)系 。
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.
首先在第一個(gè)表中創(chuàng)建一個(gè)主鍵,也稱為唯一鍵。
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.
第二個(gè)通過(guò)使用第二個(gè)表創(chuàng)建外鍵。
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.
查詢以從數(shù)據(jù)庫(kù)中找到學(xué)生的姓名,地址和聯(lián)系方式。
Conclusion:
結(jié)論:
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.
在本文中,我們學(xué)習(xí)了如何使用外鍵以及它如何工作以及對(duì)我們從關(guān)系數(shù)據(jù)庫(kù)中檢索數(shù)據(jù)有用嗎? 希望您理解這個(gè)概念; 如果您有任何疑問(wèn),請(qǐng)隨時(shí)在評(píng)論部分提問(wèn)。
翻譯自: https://www.includehelp.com/sql/how-to-use-foreign-key-in-sql.aspx
flask sql外鍵使用
總結(jié)
以上是生活随笔為你收集整理的flask sql外键使用_如何在SQL中使用外键?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [转载] 【python魔术方法】迭代器
- 下一篇: 数据库如何处理数据库太大_网络数据库中的