I need to check foreign key constraints on a schemas. I need the table name, the column name, the referenced schema, the referenced table and the referenced column. Google search tells me that I could do this using information_schema. I have some doubts regarding this approach.
- Is the information schema reliable? I have too many large databases containing too many tables and any errors would be costly
- Considering information_schema is a system database and contains info about all databases, any query will take considerably longer. Right?
Is there an alternate method to check foreign key constraints? Using SHOW CREATE TABLE and comparing queries does not seem to be a very good idea.
My application will be coded in C# (Connector:ODBC). I know there is a .NET MySQL connector which provides Foreign Key Columns collection for the getschema method (http://dev.mysql.com/doc/refman/5.0/en/connector-net-programming-connecting-connection-string.html#connector-net-programming-getschema). Does anyone know if it uses information_schema too?
I could really use some help here.
Regards,
If it isn’t, neither is your database. (Tip: it isn’t).
That depends on how you query them. Try
show indexesto see the available indexes.In theory,
show create tablequeries the information_schema in a slightly different way.In practice, and quoting the second link further up, some of the information returned between the two might be inconsistent:
Lastly, see:
Is querying the MySQL information_schema database a good way to find related tables?