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
Linda HamiltonOriginal
2024-11-03 10:02:29980browse

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;

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`)
...

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!

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