Home > Database > phpMyAdmin > body text

How to add foreign keys in phpmyadmin

下次还敢
Release: 2024-04-07 14:36:17
Original
1393 people have browsed it

Adding a foreign key in phpMyAdmin can be achieved by following these steps: Select the parent table that contains the foreign key. Edit the parent table structure and add new columns in "Columns". Enable foreign key constraints and select the referencing table and key. Set update/delete operations. save Changes.

How to add foreign keys in phpmyadmin

How to add foreign keys in phpMyAdmin

In MySQL, foreign keys are used to create two tables relationship between. In phpMyAdmin, you can add a foreign key by following these steps:

1. Select the parent table

  • In phpMyAdmin, navigate to the parent table that contains the foreign key .

2. Edit the parent table structure

  • Click the "Structure" tab of the table.

3. Add a new column

  • In the Columns section, click the Add Column button at the bottom of the table.

4. Set the data type

  • Select the data type of the new column, usually INT or BIGINT, depending on the type of the foreign key column .

5. Enable foreign key constraints

  • In the "Other" section, select the "Foreign Key" checkbox.

6. Select the reference table and key

  • Select the table referenced by the foreign key from the "Reference Table" drop-down menu.
  • Select the key column referenced by the foreign key from the "Reference Key" drop-down menu.

7. Set update/delete operation

  • In the "Update" and "Delete" tabs, select the foreign key to be updated or deleted time operation. Typically, select Cascade Update and Cascade Delete.

8. Save changes

  • Click the Save button to apply the changes.

Note:

  • Ensure that the column data type in the parent table matches the foreign key column data type in the reference table.
  • Before adding a foreign key, ensure that the key column in the reference table has been created.
  • If you add a foreign key to an existing table, you may need to rebuild the table in phpMyAdmin to activate the constraint.

The above is the detailed content of How to add foreign keys in phpmyadmin. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!