数据库中的SCHEMA到底是什么?MySQL

平时在看一些数据库相关的书籍或是文档的时候总会出现这样一个词SCHEMA(模式),那这个SCHEMA到底是指什么?下面就来看看

SHCHEMA的定义

官方文档定义

Conceptually, a schema is a set of interrelated database objects, such as tables, table columns, data types of the columns, indexes, foreign keys, and so on. These objects are connected through SQL syntax, because the columns make up the tables, the foreign keys refer to tables and columns, and so on. Ideally, they are also connected logically, working together as part of a unified application or flexible framework. For example,the INFORMATION_SCHEMA and performance_schema databases use “schema” in their names to emphasize the close relationships between the tables and columns they contain.
In MySQL, physically, a schema is synonymous with a database. You can substitute the keyword SCHEMA instead of DATABASE in MySQL SQL syntax, for example using CREATE SCHEMA instead of CREATE DATABASE.
Some other database products draw a distinction. For example, in the Oracle Database product, a schema represents only a part of a database: the tables and other objects owned by a single user.
See Also database, INFORMATION_SCHEMA, Performance Schema.

摘自: https://dev.mysql.com/doc/refman/8.0/en/ . 文档最后一部分MySQL Glossary(MySQL 术语 )

野鸡翻译

从概念上讲,schema指的是一组相关联的数据库对象,这些对象包含:表、字段、字段类型、索引、外键、等等。 这些对象通过SQL语法连接,因为表是由字段组成的,外键指向表和字段等等。理想情况下,这些对象在逻辑上也是相连的,作为统一应用程序或者是灵活框架的一部分一起运作。例如,MySQL自带的“INFORMATION_SCHEMA”和“performace_schema”数据库在数据库命名时使用了“schema”这个词,目的就在于强调该数据库包含的表和字段的亲密关系。
Mysql中,从物理层角度讲,schema就是数据库的代名词。你可以用SCHEMA关键字代替DATABASE,如:使用CREATE SCHEMA代替CREATE DATABASE.
另外,不同数据对SCHEMA的定义是不一样的。例如,在Oracle中,schema仅表示数据库的一部分:单个用户拥有的表和其他对象。

SCHEMA的例子

SCHEMA代替database

使用关键字schema代替关键字database,如在查询数据库清单或者创建数据库时,如下图:

在这里插入图片描述
如上图所示,使用show databases; 和show schemas 得到的结果是一致的。
在这里插入图片描述
在这里插入图片描述
如上图可知,create database; 和create schema;效果是一致的。

MySQL中自带的performance_schema数据库和information_schema

安装Mysql后都会自带有两个数据库performance_schema和information_schema,简单介绍如下:
在这里插入图片描述

performance_schema

顾名思义:性能模式(数据库),即是该数据库包含的表和字段是用于存储MySQL中关于性能特征的信息的。这里使用schema这个词就如定义中一样是为了强调该数据库是关于性能方面。
在这里插入图片描述

information_schema

该模式(数据库)存储的是MySQL的数据字典。比如,要查询MySQL的元数据信息可以查询表INFORMATION_SCHEMA.TABLES和INFORMATION_SCHEMA.COLUMNS来获得MySQL中的表信息和字段信息。例如:
现在要查看MySQL中存储了多少张表,就可以在information_schema数据库表TABLES中进行查询

切换到information_schema,并查看TABLES表中的数据量

在这里插入图片描述
在这里插入图片描述

也就是当前整个MySQL中存储了493张表

切换到非MySQL自带数据库,删除一张表

最好不要删除MySQL自带的表,所以这里切换到用户自定义数据库,并删除1张表
在这里插入图片描述
在这里插入图片描述

验证结果,查询informaton_schema中表TABLES中的数据量

在这里插入图片描述
数据量492 = 493 -1;
减少了1条 ,符合预期。

总结

schema(模式)就是database(数据库)的代名词。
schema强调数据库中表(或其他对象)表示(存储)内容的方向。

以下是一个基于栈的出栈序列检查的C语言代码: ```c #include <stdio.h> #include <stdlib.h> #define MAX_STACK_SIZE 100 int stack[MAX_STACK_SIZE]; int top = -1; void push(int val) { if (top == MAX_STACK_SIZE - 1) { printf("Stack overflow\n"); exit(1); } stack[++top] = val; } int pop() { if (top == -1) { printf("Stack underflow\n"); exit(1); } return stack[top--]; } int main() { int n, i, j; int push_seq[MAX_STACK_SIZE], pop_seq[MAX_STACK_SIZE]; printf("Enter the size of the sequence: "); scanf("%d", &n); printf("Enter the push sequence: "); for (i = 0; i < n; i++) { scanf("%d", &push_seq[i]); } printf("Enter the pop sequence: "); for (i = 0; i < n; i++) { scanf("%d", &pop_seq[i]); } i = 0; j = 0; while (i < n && j < n) { if (push_seq[i] == pop_seq[j]) { i++; j++; } else if (top != -1 && stack[top] == pop_seq[j]) { pop(); j++; } else { push(push_seq[i++]); } } while (top != -1 && j < n) { if (stack[top] == pop_seq[j]) { pop(); j++; } else { break; } } if (top == -1 && j == n) { printf("The pop sequence is valid.\n"); } else { printf("The pop sequence is not valid.\n"); } return 0; } ``` 该程序要求用户输入一个序列的大小,一个压栈序列和一个出栈序列。然后,程序使用一个基于栈的算法来检查出栈序列的合法性。如果出栈序列是合法的,程序将输出“ The pop sequence is valid.”,否则输出“The pop sequence is not valid.”。 该算法的基本思想是模拟压栈和出栈过程。我们从压栈序列的开头开始遍历,遇到一个和出栈序列的当前元素相等的元素时,我们将它出栈。否则,我们将该元素压入栈。如果栈顶元素和出栈序列的当前元素相等,则将栈顶元素出栈。 在遍历完压栈序列后,我们检查栈剩余的元素是否可以与出栈序列的元素匹配。如果可以,则弹出栈顶元素并移动到下一个出栈元素。如果不能匹配,则出栈序列无效。 此算法的时间复杂度为O(n),其n为序列的大小。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值