Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

How to show constraints in MySQL

Working in Postgres, I’ve gotten used to seeing the contraints on a table listed with \d. Working in MySQL I wasn’t seeing similar with describe <table>;. Turns out you can see all the constraints by selecting from information_schema.referential_constraints:

SELECT * 
  FROM information_schema.referential_constraints 
  WHERE constraint_schema='db_name' 
  AND table_name='table_of_interest';
Looking for help? Hashrocket developers believe that data quality is as important as code quality. We enjoy all the challenges of relational databases, from finding the fastest index, to structuring data to fit the needs of an application. We're eager to share our experiences; check out PG Casts, our series of free PostgreSQL screencasts.