Mysql:
Use sakila;--show fields from table_name;--show keys from table_name; SELECT ' referenced_table_name ' from ' information_schema '. ' Key_column_usage ' WHERE ' table_name ' = ' [table_containing _foreign_key] ' and ' column_name ' = ' [Foreign_key] '; SHOW COLUMNS from the city; SELECT * FROM Information_schema.tables;select * from Information_schema.tableswhere table_schema= ' Sakila '; From Information_schema.tables;select * from INFORMATION_SCHEMA. Key_column_usage;select * from INFORMATION_SCHEMA. Parameters;select * from INFORMATION_SCHEMA. Views;select * from INFORMATION_SCHEMA. triggers;--get Table/fields metadataselect table_schema, TABLE_NAME, COLUMN_NAME, ordinal_position, data_type, num Eric_precision, Column_type, Column_default, is_nullable, column_comment from Information_schema.columns--WHERE (tabl E_schema= ' Sakila ' and table_name = ' city ')--Displays the specified table WHERE table_schema= ' Sakila ' ORDER by ordinal_position; --Get foregn Keys referenced tableselect ' referenced_tablE_name ' from ' information_schema '. ' Key_column_usage ' WHERE ' table_name ' = ' city '; --' table_name ' = ' table_name ' and--' column_name ' = ' column_name '--Get indexes (primary and foreign) for a table- -Get all indexes and referreced tableselect * from ' information_schema '. ' Key_column_usage ' WHERE ' table_name ' = ' City ' and ' table_schema ' = ' Sakila '; SELECT * from ' information_schema ', ' referential_constraints ' WHERE ' table_name ' = ' city ' and ' CONSTRAINT_SC HEMA ' = ' Sakila '; --Get STORED proceduresselect * from ' information_schema '. ' ROUTINES ' WHERE ' routine_schema ' = ' sakila ';--Get TRI Ggersselect * from ' information_schema '. ' TRIGGERS ' WHERE ' trigger_schema ' = ' Sakila '; --Get Eventsselect * from ' information_schema '. ' EVENTS ' WHERE ' event_schema ' = ' Sakila '; --Get Viewsselect * from ' information_schema '. ' Views ' WHERE ' table_name ' = ' city ' and ' table_schema ' = ' Saki La '; --' COLUMNS 'EVENTS ' FILES ' TABLES ' SELECT table_schema, TABLE_NAME, COLUMN_NAME, Ordinal_position, Data_type, Numeric_precision, C Olumn_type from information_schema.columns WHERE table_name = ' TABLES ';
SQL Server:
--sql-92 standardselect table_catalog, Table_schema,table_name, column_name, Data_type, CHARACTER_MAXIMUM_LENGTH from DuVehicle.information_schema.columns; SELECT * from DuVehicle.INFORMATION_SCHEMA.PARAMETERS; Gogo/*information_schema Views:view Name Description check_constraints holds information about CONSTRAINTS in the D Atabase Column_domain_usage identifies which columns in which tables is user-defined datatypes column_privileges has one Row for each column level permission granted to or by the current user COLUMNS Lists one row for each column in each table Or view in the database Constraint_column_usage Lists one row for each COLUMN, a CONSTRAINT defined on it Constra Int_table_usage Lists one row for each TABLE the have a constraint defined on it domain_constraints Lists the user-defined Datatypes that has the rules bound to them DOMAINS Lists the user-defined datatypes key_column_usage Lists one row for each column that's defined as a key PARAMETERS Lists one row for Each parameter in a stored procedure or user-defined function referential_constraints Lists one row for each foreign cons Traint ROUTINES Lists one row for each stored procedure or user-defined function Routine_columns Contains one row for each Column returned by any table-valued functions schemata Contains one row for each database table_constraints Lists one row For each constraint defined in the current database table_privileges have one row for each TABLE level permission granted To or by the current user TABLES Lists one row for each table or view in the current database View_column_usage Lists one Row for each column in a view including the base table of the column where possible view_table_usage Lists one row for EAC H table used in a view Lists one row for each view*/
SQL Server Metadata Toolkit 2005-2014 https://sqlmetadata.codeplex.com/
MySQL and SQL server:getting Metadata using SQL script (SQL-92 standard)