Home  >  Article  >  Database  >  How to add constraints in navicat

How to add constraints in navicat

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-08-03 14:36:2515150browse

How to add constraints in navicat

Open the navicat tool to connect to the mysql service, and then choose to open a database. Here, a test database is selected for demonstration, and then foreign keys for the user table and school table are selected. Select the t_user table and click Design Table.

How to add constraints in navicat

On the design table page, the default is the field page. Here you can edit the field content for the table. We select the foreign key option.

How to add constraints in navicat

Related recommendations: "Navicat for mysql graphic tutorial"

Foreign key setting page, select the second column field For the button on the right, you can leave the first column blank and a foreign key name will be automatically generated. You can customize one if you need to standardize the naming.

How to add constraints in navicat

In the field drop-down list that pops up, select a field to which you want to add a foreign key. Here we are adding a foreign key to the school table, so select school_id.

How to add constraints in navicat

#Then select the reference table, which is the table pointed to by the foreign key. The reference database does not need to be selected. The default is the current database. Reference table selection school table t_school_info.

How to add constraints in navicat

Refer to the selection of fields, because the two tables are bound by id association, just select id here.

How to add constraints in navicat

The last is the constraint rules when deleting and updating. If you choose cascade deletion CASCADE, the school table data deletion will cascade delete the user data. You can also choose the RESTRICT constraint method. You must first delete all users associated with a school before you can delete school information.

How to add constraints in navicat

#After completing the above selections, click Save, and then the foreign key constraints will take effect. You can edit the data in the table to see the effect.

How to add constraints in navicat

The above is the detailed content of How to add constraints 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