当前位置:网站首页>SCHEMA解惑
SCHEMA解惑
2022-08-01 11:05:00 【华为云】
一、定义
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名。
边栏推荐
- [Cloud Residency Co-Creation] Huawei Cloud Global Scheduling Technology and Practice of Distributed Technology
- Google Earth Engine APP——15行代码搞定一个inspector高程监测APP
- 【likeshop】回收租凭系统100%开源无加密 商城+回收+租赁
- Small application project works WeChat gourmet recipes applet graduation design of finished product (1) the development profile
- 深度学习 | MATLAB实现GRU门控循环单元gruLayer参数设定
- Promise learning (4) The ultimate solution for asynchronous programming async + await: write asynchronous code in a synchronous way
- How to Steal $100 Million from the Perfect Smart Contract
- ACL 2022 | 文本生成的相关前沿进展
- gc的意义和触发条件
- PDMan-国产免费通用数据库建模工具(极简,漂亮)
猜你喜欢

在线GC日志分析工具——GCeasy

C#/VB.NET 将PPT或PPTX转换为图像

A new generation of ultra-safe cellular batteries, Sihao Airun goes on sale starting at 139,900 yuan

Jenkins安装插件遇到的问题
退役划水

jmeter

C#/VB.NET convert PPT or PPTX to image

CTFshow,命令执行:web37
retired paddling

Endorsed in 2022 years inventory | product base, science and technology, guangzhou automobile group striding forward
随机推荐
WPF 截图控件之绘制箭头(五)「仿微信」
ModelArts-based object detection YOLOv3 practice [play with HUAWEI CLOUD]
2022年7月31日--使用C#迈出第一步--使用C#中的数组和foreach语句来存储和循环访问数据序列
基于ArkUI eTS开发的坚果食谱(NutRecipes)
小程序毕设作品之微信美食菜谱小程序毕业设计成品(3)后台功能
(ES6以上以及TS) Map对象转数组
判断JS数据类型的四种方法
MFC实现交通图导航系统
C#/VB.NET 将PPT或PPTX转换为图像
Promise to learn several key questions (3) the Promise - state change, execution sequence and mechanism, multitasking series, abnormal penetration, interrupt the chain of Promise
.NET analyzes the LINQ framework in depth (three: the elegant prelude of LINQ)
Flutter Widget 如何启用和屏蔽点击事件
DBPack SQL Tracing 功能及数据加密功能详解
What is a stepper motor?40 pictures to show you!
广域铭岛入选2022年重庆市数字经济产业发展试点示范项目名单
pve 删除虚拟机「建议收藏」
redis6 跟着b站尚硅谷学习
CTFshow,命令执行:web34、35、36
jmeter
数字化转型实践:世界级2B数字化营销的方法框架