Home  >  Article  >  Database  >  使用SQL查询所有数据库名和表名

使用SQL查询所有数据库名和表名

PHPz
PHPzforward
2016-06-07 15:55:541952browse

MySQL中查询所有数据库名和表名

查询所有数据库

<span style="font-size: 14px;">show databases;<br/></span>

查询指定数据库中所有表名

<span style="font-size: 14px;">select table_name from information_schema.tables where table_schema=&#39;database_name&#39; and table_type=&#39;base table&#39;;<br/></span>

查询指定表中的所有字段名

<span style="font-size: 14px;">select column_name from information_schema.columns where table_schema=&#39;database_name&#39; and table_name=&#39;table_name&#39;;<br/></span>

查询指定表中的所有字段名和字段类型

<span style="font-size: 14px;">select column_name,data_type from information_schema.columns where table_schema=&#39;database_name&#39; and table_name=&#39;table_name&#39;;<br/></span>

SQLServer中查询所有数据库名和表名

查询所有数据库

<span style="font-size: 14px;">select * from sysdatabases;<br/></span>

查询当前数据库中所有表名

<span style="font-size: 14px;">select * from sysobjects where xtype=&#39;U&#39;;<br/>xtype=&#39;U&#39;:表示所有用户表,xtype=&#39;S&#39;:表示所有系统表。<br/></span>

查询指定表中的所有字段名

<span style="font-size: 14px;">select name from syscolumns where id=Object_Id(&#39;table_name&#39;);<br/></span>

查询指定表中的所有字段名和字段类型

<span style="font-size: 14px;">select sc.name,st.name from syscolumns sc,systypes st where sc.xtype=st.xtype and sc.id in(select id from sysobjects where xtype=&#39;U&#39; and name=&#39;table_name&#39;);<br/></span>

Oracle中查询所有数据库名和表名

查询所有数据库

由于Oralce没有库名,只有表空间,所以Oracle没有提供数据库名称查询支持,只提供了表空间名称查询。

<span style="font-size: 14px;">select * from v$tablespace;--查询表空间(需要一定权限)<br/></span>

查询当前数据库中所有表名

<span style="font-size: 14px;">select * from user_tables;<br/></span>

查询指定表中的所有字段名

<span style="font-size: 14px;">select column_name from user_tab_columns where table_name = &#39;table_name&#39;;<br/></span>

查询指定表中的所有字段名和字段类型

<span style="font-size: 14px;">select column_name, data_type from user_tab_columns where table_name = &#39;table_name&#39;;<br/></span>

更多相关教程请访问   MySQL视频教程

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete