flask sql外键使用_如何在SQL中使用外键?

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:

Foreign-table-1

Table 2:

表2:

Foreign-table-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.

查询以从数据库中找到学生的姓名,地址和联系方式。

Foreign result

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外键使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值