search
HomeDatabasenavicatHow to establish relationships between tables in navicat

How to establish relationships between tables in navicat

Navicat is a set of fast, reliable and relatively cheap database management tools, designed to simplify database management and reduce system management costs. It is designed to meet the needs of database administrators, developers and small and medium-sized businesses. Below we will introduce to you how navicat establishes relationships with tables.

Recommended tutorial: navicat graphic tutorial

##The relationship between tables in the database is reflected by a foreign key . So to establish a relationship between two tables, you actually create a foreign key to the table.

1. Open navicat, select the database table to be operated, right-click and select Design Table.


How to establish relationships between tables in navicat

#2. Click the foreign key option to start setting foreign keys.

How to establish relationships between tables in navicat

There are seven columns in total. Let’s briefly introduce the meaning of these columns:

“Name”: You don’t need to fill it in. The system will automatically generate it after you save it successfully.

"Field": It means which key you want to set as a foreign key.

"Reference database": Database associated with foreign keys.

"Reference table": associated table

"Reference field": associated field,

"When deleting": It is the action selected when deleting.

"When updating": It is the action selected when updating.

Extended information: The role of foreign keys

 

Maintain data consistency and integrity, the main purpose is to control the storage in foreign key tables The data in . To associate two tables, the foreign key can only refer to the values ​​of columns in the table or use null values.

If no foreign key is used, a value (such as 20140999999) is inserted into the student number field of Table 2, but this value does not exist in Table 1. At this time, the database allows the insertion and will not block the inserted value. Data is checked for relationships. However, when setting up a foreign key, the value you insert into the student ID field of Table 2 must be found in the student ID field of Table 1. At the same time, if you want to delete a certain student number field in Table 1, you must ensure that there is no column in Table 2 that references the field value, otherwise it will not be deleted. This is called maintaining data consistency and integrity. As shown on the right, if Table 2 still references a certain student ID in Table 1, but you delete the student ID in Table 1, Table 2 will not know which student the student ID corresponds to.

The tables in the database must comply with the specifications to prevent data redundancy, insertion anomalies, deletion anomalies and other phenomena. The canonical process is the process of decomposing the table. After decomposition, the representative attributes of a thing appear in different tables. Obviously, they should be consistent. For example, the representative data of a student is student number 012, which is 012 in the student table and should also be 012 in the grade table. This consistency is achieved by foreign keys. The function of a foreign key is: its value must be the primary key value of another table. The student number is the primary key in the student table and the foreign key in the grades table. The student number in the grade list must be the student number in the student list. Therefore, the student number in the student table and the student number in the grade table are consistent. It can be intuitively understood that the function of foreign keys is to achieve consistency of signs of the same thing in different tables. 2 Functional realization of two tables connected by foreign keys. When operated separately, the foreign key function is realized by two methods [4]: ​​

Prevent execution

 ●Insert a new row from the table, and the foreign key value is not the primary key value of the main table, which prevents the insertion;

 ●Modify the foreign key value from the table, and the new value is not the primary key of the main table The value will prevent modification;

●If a row is deleted from the master table, its primary key value will be prevented from being deleted if it exists in the slave table (if you want to delete it, you must first delete the relevant rows from the slave table);

●The master table modifies the primary key value. If the old value exists in the slave table, the modification is blocked (if you want to modify it, you must first delete the relevant rows from the slave table).

Cascade execution

●Delete rows from the main table, and delete related rows from the table together;

●Modify the primary key value from the main table, Modify the foreign key values ​​of related rows from the table together. Two methods are provided for users to choose. No matter which method is chosen, there will be no extra rows from the table. From another perspective, the same thing is achieved by rejecting the inconsistency between the flags in the slave table and the master table to achieve consistency with the flags in the master table.

 ●Two implementation methods, choose through the following methods:

●Interface: Set up two selection boxes for cascade update and cascade delete. If selected, the cascade will be executed, and if not selected, it will be blocked. Execution;

●Command: Let E)kSCM)E and RESTRICT be two optional options, CASCADE means cascade execution, and RESTRICT means prevent execution.

The above is the detailed content of How to establish relationships between tables in navicat. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Navicat连接MySQL提示1045错误怎么解决Navicat连接MySQL提示1045错误怎么解决Jun 02, 2023 pm 11:13 PM

错误提示:1045-Accessdeniedforuser'root''localhost'(usingpassword:YES)navicat连接MySQL数据时遇到1045错误,一般是因为输入的用户名或者密码错误被拒绝访问,此时可以重置MySQL数据库的密码解决。在windows的操作步骤如下:1、找到mysql的my.ini文件,在mysqld关键字下面添加skip-grant-tables,如下图所示:该命令作用是跳过授权表

浅析Navicat如何修改语言(中文or英文)?浅析Navicat如何修改语言(中文or英文)?Jul 05, 2022 am 10:19 AM

Navicat如何修改语言?下面本篇文章给大家介绍一下将Navicat Premium 的语言改成中文/英文的方法,希望对大家有所帮助!

navicat premium怎么连接mongodbnavicat premium怎么连接mongodbApr 06, 2024 am 06:51 AM

本文介绍了如何使用 Navicat Premium 连接 MongoDB,具体步骤如下:建立连接:在 Navicat Premium 中,选择连接选项卡,并在数据库类型中选择 MongoDB。配置连接设置:输入连接名称、主机地址、端口号、用户名、密码和数据库名称。设置高级选项(可选):配置重连次数、重连间隔、SSL 加密和认证数据库。保存连接:单击保存按钮即可创建连接。

navicat premium怎么导入数据库文件navicat premium怎么导入数据库文件Apr 06, 2024 am 06:57 AM

使用 Navicat Premium 导入数据库文件的步骤如下:连接到目标数据库。导航到“导入向导”。选择要导入的文件。配置导入设置。开始导入。验证导入结果。

navicat premium怎么连接数据库备份还原navicat premium怎么连接数据库备份还原Apr 06, 2024 am 06:48 AM

在 Navicat Premium 中连接数据库备份并还原数据:连接备份:在“连接”对话框中输入服务器信息、登录凭据,并在“数据库”字段选择备份文件。还原数据:右键单击目标数据库,选择“还原”,选择“从备份还原”并浏览备份文件。配置选项:指定覆盖数据、还原表结构等选项。开始还原:单击“开始”执行还原过程。更新连接:还原后,更新连接信息指向还原后的数据库。

Navicat for MySQL如何连接本地MySQL数据库-Navicat for MySQL连接本地MySQL数据库的方法Navicat for MySQL如何连接本地MySQL数据库-Navicat for MySQL连接本地MySQL数据库的方法Mar 04, 2024 pm 07:30 PM

本章节为你们带来的文章是关于NavicatforMySQL软件的,你们晓得NavicatforMySQL如何连接本地MySQL数据库吗?接着,小编就为各位带来了NavicatforMySQL连接本地MySQL数据库的方法,感兴趣的用户一同来下文看看吧。进行打开电脑Navicatformysql已经安装好的,然后进行点击右上角的“连接”选项在弹出的新建连接窗口中,您可以输入连接名称,并将主机名设置为本地数据库,因此只需使用“localhost”,密码留空即可。然后方便连接的数据库是否连接成功的话,

navicat怎么在表中添加数据navicat怎么在表中添加数据Apr 06, 2024 am 07:36 AM

Navicat中向表中添加数据的步骤:1. 连接数据库;2. 定位目标表;3. 打开数据编辑器;4. 添加新行;5. 输入数据;6. 提交更改(保存或按F2键)。

navicat premium怎么运行不了navicat premium怎么运行不了Apr 06, 2024 am 07:33 AM

解决 Navicat Premium 无法运行问题的方法:确保系统符合要求,安装 Microsoft Visual C++ 可再发行组件。以管理员身份运行 Navicat Premium,禁用防病毒软件,检查防火墙设置。如果以上步骤无效,请重新安装 Navicat Premium。寻求 Navicat 支持团队的帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.