Navicat Adding a foreign key detail procedure in MySQL

Source: Internet
Author: User

Navicat Adding a foreign key detail procedure in MySQL

/**

* @author Blovedr

* function: navicat add foreign key in MySQL

* Date: June 21, 2018 22:42

* Note: Learn the database MySQL point of record, thank you online the great God to share experience, welcome the great God of criticism and guidance and communication.

*/

1. Open the Navicat connection on the database and create a new database: "test";

2. Create two table "emp" (primary table) and "dept" (from table) in database "test"

"emp" (Main Table---employee table)

"dept" (from Table---Department table)

3. Set the "emp" (Main Table) and "dept" (from the table) options

Table type:InnoDB,

Character Set: Utf8–utf-8 Unicode (default),

Collation: Utf8_general_ci (default),

Auto Increment : Set yourself (the primary table EMP must be the same as from table dept)

4 . Set foreign keys

FOREIGN Key Name (name): Can not fill, the system automatically generated;

Field name (Field Name): Just set 'dept_id' as the foreign key ;

Reference Database (Reference dadabase): The database associated with the foreign key (' dept_id ');

reference table (Reference table): The associated table , here is the dept table ;

Outer column name (Outside field name): The associated field (here is "dept_id", which can be the same as the column name);

Delete : Delete time selected action (here Select CASCADE);

Refresh : The action selected when updating (choose CASCADEhere)CASCADE--- That is, when the associated table is updated, the dept_id in the EMP is updated as well .

Note : The Add foreign key database engine must be InnoDB;

The associated field data type must be the same;

The associated field data from the table must be in the primary table.

5. Use navicat to add foreign keys to MySQL .

Navicat Adding a foreign key detail procedure in MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.