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 City;
select * from information_schema.tables;
select * from information_schema.tables
where table_schema='sakila';
select * 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 metadata
SELECT table_schema, table_name, column_name, ordinal_position, data_type,
numeric_precision, column_type, column_default, is_nullable, column_comment
FROM information_schema.columns
-- WHERE (table_schema='sakila' and table_name = 'city') -- 显示指定表
WHERE table_schema='sakila'
order by ordinal_position;
-- get Foregn Keys referenced table
SELECT `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 table
SELECT *
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_SCHEMA` = 'sakila';
-- get STORED PROCEDURES
SELECT *
FROM `information_schema`.`ROUTINES`
WHERE
`ROUTINE_SCHEMA` = 'sakila';
-- get TRIGGERS
SELECT *
FROM `information_schema`.`TRIGGERS`
WHERE
`TRIGGER_SCHEMA` = 'sakila';
-- get EVENTS
SELECT *
FROM `information_schema`.`EVENTS`
WHERE
`EVENT_SCHEMA` = 'sakila';
-- get VIEWS
SELECT *
FROM `information_schema`.`VIEWS`
WHERE
`TABLE_NAME` = 'city' AND
`TABLE_SCHEMA` = 'sakila';
-- 'COLUMNS' 'EVENTS' 'FILES' 'TABLES'
SELECT table_schema, table_name, column_name, ordinal_position, data_type, numeric_precision, column_type FROM information_schema.columns
WHERE table_name = 'TABLES';
--SQL-92 standard
select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH from DuVehicle.information_schema.columns;
SELECT * FROM DuVehicle.INFORMATION_SCHEMA.PARAMETERS;
GO
GO
/*INFORMATION_SCHEMA views:
View Name Description
CHECK_CONSTRAINTS Holds information about constraints in the database
COLUMN_DOMAIN_USAGE Identifies which columns in which tables are 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 that has a constraint defined on it
CONSTRAINT_TABLE_USAGE Lists one row for each table that has a constraint defined on it
DOMAIN_CONSTRAINTS Lists the user-defined datatypes that have 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 pr