How to get all columns’ names for all the tables in MySQL?
select column_name from information_schema.columns where table_schema=”your_db” order by table_name,ordinal_position
select column_name from information_schema.columns where table_schema=”your_db” order by table_name,ordinal_position
You need to iterate over your ResultSet calling next(). This is an example from java2s.com: DatabaseMetaData md = conn.getMetaData(); ResultSet rs = md.getTables(null, null, “%”, null); while (rs.next()) { System.out.println(rs.getString(3)); } Column 3 is the TABLE_NAME (see documentation of DatabaseMetaData::getTables).
I use Nigel’s approach (extracting table name from .ToTraceString()) but with some modifications, because his code won’t work if the table is not in the default SQL Server schema (dbo.{table-name}). I’ve created extension methods for DbContext and ObjectContext objects: public static class ContextExtensions { public static string GetTableName<T>(this DbContext context) where T : class { … Read more
The referenced primary key is described in the columns r_owner and r_constraint_name of the table ALL_CONSTRAINTS. This will give you the info you want: SELECT a.table_name, a.column_name, a.constraint_name, c.owner, — referenced pk c.r_owner, c_pk.table_name r_table_name, c_pk.constraint_name r_pk FROM all_cons_columns a JOIN all_constraints c ON a.owner = c.owner AND a.constraint_name = c.constraint_name JOIN all_constraints c_pk ON … Read more