当前位置:网站首页>SCHEMA solves the puzzle
SCHEMA solves the puzzle
2022-08-01 11:33:00 【HUAWEI CLOUD】
一、定义
A schema is a collection of database objects (used by a user.). Schema objects are the logical structures that directly refer to the database’s data. A user is a name defined in the database that can connect to and access objects .Schemas and users help database administrators manage database security.
从定义中我们可以看出schema为数据库对象的集合,为了区分各个集合,我们需要给这个集合起个名字,这些名字就是我们在企业管理器的方案下看到的许多类似用户名的节点,这些类似用户名的节点其实就是一个schema,schema里面包含了各种对象如tables, views, sequences, stored procedures, synonyms, indexes, clusters, and database links.
一个用户一般对应一个schema,该用户的schema名等于用户名,并作为该用户缺省schema.这也就是我们在企业管理器的方案下看到schema名都为数据库用户名的原因.
Oracle数据库中不能新创建一个schema,要想创建一个schema,只能通过创建一个用户的方法解决(Oracle中虽然有create schema语句,但是它并不是用来创建一个schema的),在创建一个用户的同时为这个用户创建一个与用户名同名的schem,并作为该用户的缺省shcema.即schema的个数同user的个数相同,而且schema名字同user名字一一对应并且相同,所有我们可以称schema为user的别名,虽然这样说并不准确,但是更容易理解一些.
一个用户有一个缺省的schema,其schema名就等于用户名,当然一个用户还可以使用其他的schema.如果我们访问一个表时,没有指明该表属于哪一个schema中的,系统就会自动给我们在表上加上缺省的sheman名.比如我们在访问数据库时,访问scott用户下的emp表,通过select * from emp; 其实,这sql语句的完整写法为select * from scott.emp.在数据库中一个对象的完整名称为schema.object,而不属user.object.类似如果我们在创建对象时不指定该对象的schema,在该对象的schema为用户的缺省schema.这就像一个用户有一个缺省的表空间,但是该用户还可以使用其他的表空间,如果我们在创建对象时不指定表空间,则对象存储在缺省表空间中,要想让对象存储在其他表空间中,我们需要在创建对象时指定该对象的表空间.
二、举例
SQL> Gruant dba to scottSQL> create table test(name char(10));Table created.SQL> create table system.test(name char(10));Table created.SQL> insert into test values('scott'); 1 row created.SQL> insert into system.test values('system');1 row created.SQL> commit;Commit complete.SQL> conn system/managerConnected.SQL> select * from test;NAME----------systemSQL> ALTER SESSION SET CURRENT_SCHEMA = scott; --改变用户缺省schema名Session altered.SQL> select * from test;NAME----------scottSQL> select owner ,table_name from dba_tables where table_name=upper('test');OWNER TABLE_NAME------------------------------ ------------------------------SCOTT TESTSYSTEM TEST上面这个查询就是我说将schema作为user的别名的依据.实际上在使用上,shcema与user完全一样,没有什么区别,在出现schema名的地方也可以出现user名.
边栏推荐
- Golang内存分析工具gctrace和pprof实战
- EasyRecovery热门免费数据检测修复软件
- R语言拟合ARIMA模型:使用forecast包中的auto.arima函数自动搜索最佳参数组合、模型阶数(p,d,q)、设置seasonal参数指定在模型中是否包含季节信息
- Istio Meetup China:全栈服务网格 - Aeraki 助你在 Istio 服务网格中管理任何七层流量
- 2022 Go ecosystem rpc framework Benchmark
- Small application project works WeChat gourmet recipes applet graduation design of finished product (1) the development profile
- WPF 截图控件之绘制箭头(五)「仿微信」
- 深度学习 | MATLAB实现一维卷积神经网络convolution1dLayer参数设定
- 一篇文章,带你详细了解华为认证体系证书(1)
- 【社区明星评选】第24期 8月更文计划 | 笔耕不辍,拒绝躺平!更多原创激励大礼包,还有华为WATCH FIT手表!
猜你喜欢
![[5 days countdown] to explore the secret behind the great quality promotion, gift waiting for you to take of $one thousand](/img/de/1e6069e84183d1400c90a6ec574f72.png)
[5 days countdown] to explore the secret behind the great quality promotion, gift waiting for you to take of $one thousand

Promise学习(四)异步编程的终极解决方案async + await:用同步的方式去写异步代码

小程序插件如何帮助开发者受益?

leetcode/submatrix element sum

STM32 CAN filter configuration details

一文说明白ECDSA spec256k1 spec256r1 EdDSA ed25519千丝万缕的关系

2022 Go ecosystem rpc framework Benchmark

一篇文章,带你详细了解华为认证体系证书(1)

判断JS数据类型的四种方法

.NET性能优化-使用SourceGenerator-Logger记录日志
随机推荐
C#/VB.NET 将PPT或PPTX转换为图像
JS 中的 undefined 和 null 的区别
R语言诊断ARIMA模型:forecast包构建了一个ARIMA模型、使用checkresiduals函数诊断ARIMA模型、并进行结果解读(拟合较差的ARIMA模型具有的特点)
MySQL常用语句总结
A new generation of ultra-safe cellular batteries, Sihao Airun goes on sale starting at 139,900 yuan
Sparse representation - study notes
Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器
R语言ggplot2可视化:使用ggpubr包的ggscatter函数可视化散点图、使用xscale函数指定X轴坐标轴度量调整方式、设置x轴坐标为scientific使用科学计数法显示坐标值
进制与转换、关键字
Favorites|Mechanical Engineer Interview Frequently Asked Questions
Pytest e-commerce project combat (below)
MFC implementation road map navigation system
Promise学习(四)异步编程的终极解决方案async + await:用同步的方式去写异步代码
万字解析:vector类
2022 Go生态圈 rpc 框架 Benchmark
正则表达式
bat倒计时代码
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
【随心笔记】假期快过去了,都干了点什么
一篇文章,带你详细了解华为认证体系证书(2)