当前位置:网站首页>How to use Navicat to create an associated primary foreign key for two tables
How to use Navicat to create an associated primary foreign key for two tables
2022-06-10 06:54:00 【Brother Xiaohao learns programming】
First, understand the definition of primary and foreign keys
Primary key : It's the only way to identify a record , There can be no repetition , Not allowed to be empty , To ensure data integrity .
Foreign keys : Is the primary key of another table , Foreign keys can have duplicate , It can be null , Used to make connections with other tables . So when it comes to foreign keys , It must involve at least two tables .
For example, department table and employee table :
Id=Dept_id, and Dept_id Is the foreign key in the employee table : Because the employees in the employee table need to know which department they belong to , You can use foreign keys Dept_id Find the corresponding department , Then you can find various field information in the Department table , So that the two tables are related . So , Foreign keys must be created from tables , So as to find the connection with the main table ; From the table is responsible for maintaining the relationship between the two .
The next in Navicat Set foreign keys inside
First step : Check the configuration 
Interview questions : What storage engine does your database use ? The difference is that ?
answer : Common are MyISAM and InnoDB.
MyISAM: Foreign key constraints are not supported . Unsupported transaction . When mass importing data , It will insert data and build indexes at the same time , So in order to improve execution efficiency , You should disable indexing first , Open the index after the full import .
InnoDB: Support for foreign key constraints , Support transactions . Indexes are handled separately , No reference index required .
The second step : Create an index for the column corresponding to the foreign key 
After completing the above configuration, start to set the foreign key !
RESTRICT( Limit ): If you want to delete the main table , Below it, there are records corresponding to the slave table , This master table will not be deleted .
CASCADE( cascade ): If the record of the main table is deleted , The associated records in the table will be deleted .
thus , The association between the two tables has been established !
边栏推荐
- 我的作文题目是——《我的区长父亲》
- Saccadenet: use corner features to fine tune the two stage prediction frame | CVPR 2020
- Local storage of JS data interaction
- TeleyeControlor V8.16发布 完成注册表功能
- Jumping game II
- Shardingsphere practice (6) - elastic scaling
- bson,json
- Unlock TRPC high performance password: introduction to network scheme!
- Ytu - C language exercises half search
- Matlab: 多项式表示及其基本运算
猜你喜欢

Summary of CUDA parallel computing optimization strategies

在 Kubernetes 中基于 StatefulSet 部署 MySQL(上)

Successfully solved: importerror: cannot import name 'import' from 'sklearn preprocessing

Go zero micro Service Practice Series (II. Service splitting)

go-zero 微服务实战系列(二、服务拆分)

pyinstaller

Opengauss database ODBC environment connection configuration (Windows)

TeleyeControlor V8.16发布 完成注册表功能

tensorflow实验九----------泰坦尼克号

刘勇智:一码通缺陷分析与架构设计方案丨声网开发者创业讲堂 Vol.02
随机推荐
Leetcode第 79 场双周赛-完成所有题目
Where will the alarm messages go? Fly in the flying book
一举刷新 54 个中文 NLP 任务基准,ERNIE3.0加持下的EasyDL可能是市面上最好用的NLP开发平台...
CMD of Jerry's AI protocol_ SET_ BLE_ Format of visibility command [chapter]
Address of the original blog
Notes for beginners
Unlock TRPC high performance password: introduction to network scheme!
LabVIEW controls Arduino to realize infrared ranging (advanced chapter-6)
刘勇智:一码通缺陷分析与架构设计方案丨声网开发者创业讲堂 Vol.02
Leetcode-473. 火柴拼正方形:一个4X15的皇后问题(其实就是一个回溯法)
TeleyeControlor V8.16发布 完成注册表功能
想要粽子可以,但是得经过我的认证授权才可以
Qt--- create dialog box 3: implementation of shape variable dialog box
键盘事件与表单事件
小程序:滚动到页面顶部或者某个元素位置
2022-2027 (New Edition) report on the prospect and future development of China's property rights trading industry
Matlab: 多项式表示及其基本运算
TeleyeControlor V8.47版本发布 更改Socket框架
TAP 系列文章 2 | Tanzu Application Platform v1.1 安装配置步骤
简述静态网页和动态网页的区别 Webl.0 和 Web2.0 的区别 简述 GET 和 POST 方法的区别