数据库-----catalog与schema简介 转载

在SQL环境下Catalog和Schema都属于抽象概念,主要用来解决命名冲突问题

一个数据库系统包含多个Catalog,每个Catalog包含多个Schema,每个Schema包含多个数据库对象(表、视图、字段等)

如数据库对象表的全限定名可表示为:Catalog名.Schema名.表名

SQL标准并不要求每个数据库对象的完全限定名称是唯一的,就象域名一样,如果喜欢的话,每个IP地址都可以拥有多个域名

从实现的角度来看,各种数据库系统对Catalog和Schema的支持和实现方式千差万别,比较简单而常用的实现方式是使用数据库名作为Catalog名,使用用户名作为Schema名,具体可参见下表:

供应商

Catalog支持

Schema支持

Oracle

不支持

Oracle User ID

MySQL

不支持

数据库名

MS SQL Server

数据库名

对象属主名,2005版开始有变

DB2

指定数据库对象时,Catalog部分省略

Catalog属主名

Sybase

数据库名

数据库属主名

Informix

不支持

不需要

PointBase

不支持

数据库名

 使用sql查询所以数据库名和表名以及字段

MySQL中查询所有数据库名和表名
1.查询所有数据库
show databases;

2.查询指定数据库中所有表名
select table_name from information_schema.tables where table_schema='database_name' and table_type='base table';

3.查询指定表中的所有字段名
select column_name from information_schema.columns where table_schema='database_name' and table_name='table_name';

4.查询指定表中的所有字段名和字段类型
select column_name,data_type from information_schema.columns where table_schema='database_name' and table_name='table_name';

 

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

1.查询所有数据库
select * from sysdatabases;

2.查询当前数据库中所有表名
select * from sysobjects where xtype='U';
xtype='U':表示所有用户表,xtype='S':表示所有系统表。


3.查询指定表中的所有字段名
select name from syscolumns where id=Object_Id('table_name');

4.查询指定表中的所有字段名和字段类型
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.查询所有数据库
由于Oralce没有库名,只有表空间,所以Oracle没有提供数据库名称查询支持,只提供了表空间名称查询。
select * from v$tablespace;--查询表空间(需要一定权限)

2.查询当前数据库中所有表名
select * from user_tables;

3.查询指定表中的所有字段名
select column_name from user_tab_columns where table_name = 'table_name';--表名要全大写

4.查询指定表中的所有字段名和字段类型
select column_name, data_type from user_tab_columns where table_name = 'table_name';--表名要全大写