Home > Database > Mysql Tutorial > How to Verify Primary and Foreign Key Constraints Using SHOW CREATE TABLE?

How to Verify Primary and Foreign Key Constraints Using SHOW CREATE TABLE?

Linda Hamilton
Release: 2024-11-03 10:02:29
Original
984 people have browsed it

How to Verify Primary and Foreign Key Constraints Using SHOW CREATE TABLE?

How to Verify Primary and Foreign Key Constraints

To ensure that primary key and foreign key relationships have been set up correctly, you can use the SHOW CREATE TABLE command.

Example:

To verify constraints on the practices and cred_insurances tables in the credentialing1 database, use the following command:

SHOW CREATE TABLE credentialing1.practices;
Copy after login

Output:

The output of the command will include the CREATE TABLE statement that defined the table, including all its columns, data types, and constraints. For example:

...
ALTER TABLE `practices` ADD CONSTRAINT `FK_cred_insurances` FOREIGN KEY (`cred_insurance_id`) REFERENCES `cred_insurances` (`id`),
ALTER TABLE `cred_insurances` ADD CONSTRAINT `FK_practices` FOREIGN KEY (`practice_id`) REFERENCES `practices` (`id`)
...
Copy after login

This output shows that the cred_insurance_id column in the practices table is a foreign key referencing the id column in the cred_insurances table, and vice versa.

The above is the detailed content of How to Verify Primary and Foreign Key Constraints Using SHOW CREATE TABLE?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template