Home >Database >Mysql Tutorial >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!