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

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

PHPz
Release: 2018-09-30 11:27:28
forward
2012 people have browsed it

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

查询所有数据库

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

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

<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>
Copy after login

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

<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>
Copy after login

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

<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>
Copy after login

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

查询所有数据库

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

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

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

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

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

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

<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>
Copy after login

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

查询所有数据库

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

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

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

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

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

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

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

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

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

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template