MySQL/Oracle查询数据库下所有表名

MySQL:

//查询数据库下所有表名

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '数据库名'

// 找出主键的列的名称

SELECT    c.COLUMN_NAME colname FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t, 
INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c  WHERE t.TABLE_NAME = c.TABLE_NAME 
and t.TABLE_NAME=' 
表名' and t.TABLE_SCHEMA='数据库名'  AND t.CONSTRAINT_TYPE = 'PRIMARY KEY'

//查询表中的所有列

select distinct column_name,data_type,character_maximum_length,column_key,column_comment "
 + " from information_schema.columns where table_name = '表名' and TABLE_SCHEMA='数据库名'

Oracle:

//查询数据库下所有表名

SELECT * FROM USER_TABLES  order by TABLE_NAME

// 找出主键的列的名称

select cu.* from user_cons_columns cu, user_constraints au  where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' and au.table_name = '表名.toUpperCase()'

//查询表中的所有列

select t.*,c.COMMENTS from user_tab_columns t,user_col_comments c where t.table_name = c.table_name and t.column_name = c.column_name and t.table_name = '表名.toUpperCase()'

猜你喜欢

转载自blog.csdn.net/m0_37787662/article/details/87940178