Use SQL to query all database names and table names of mysql, sersql, oracle

Use SQL to query all database names and table names

MySQL

  • 1. Query all databases
show databases;
  • 2. Query all table names in the specified database
use 数据库名
show tables

or

select table_name from information_schema.tables where table_schema='数据库名' and table_type='BASE TABLE';
  • 3. Query all field names in the specified table
select column_name from information_schema.columns where table_schema='数据库名' and table_name='表名';
  • 4. Query all field names and field types in the specified table
show create table 表名;

or

select column_name,data_type from information_schema.columns where table_schema='数据库名' and table_name='表名';

SQLServer

  1. query all databases
select * from sysdatabases;
  1. Query all table names in the current database
select * from sysobjects where xtype='U';
xtype='U':表示所有用户表,xtype='S':表示所有系统表。
  1. Query all field names in the specified table
select name from syscolumns where id=Object_Id('table_name');
  1. Query all field names and field types in the specified table
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='U' and name='table_name');

Oracle

  1. Query all databases
    Since Oralce has no database name, only table space, so Oracle does not provide database name query support, only provides table space name query.
select * from v$tablespace;--查询表空间(需要一定权限)
  1. Query all table names in the current database
select * from user_tables;
  1. Query all field names in the specified table
select column_name from user_tab_columns where table_name = 'table_name';--表名要全大写
  1. Query all field names and field types in the specified table
select column_name, data_type from user_tab_columns where table_name = 'table_name';--表名要全大写

Guess you like

Origin blog.csdn.net/zch981964/article/details/130315624