What is the schema in the database?

reference resources: http://database.guide/what-is-a-database-schema/

In database, schema (pronounced “skee MUH” or “skee MAH”, called schema in Chinese) is the organization and structure of database. Both schema and schemata can be used as plural forms. Schema objects include table, column, data type, view, stored procedures, relationships, primary key, foreign key, etc. Database schema can be represented by a visual graph, which shows database objects and their relationships

 

The above is a simple example of a schema diagram, showing three tables and their data types, the relationship between tables, and primary and foreign keys. The following is a more complex example of a database schema.

 

In this case, the pattern diagram is divided into four parts

(1) Customer data: data related to customers, such as name, address, etc

(2) Business: data needed by the business, such as employees, store location, payment details, etc

(3) Inventory: details of all products. Here, the product is a movie, so it contains movie title, category, actor and other data.

(4) Views: special views on the data used for evaluation, so we can further create a database through these schema diagrams. In fact, MySQL workbench allows us to generate a create database directly from the diagram Table script, and then we can directly use this script to create a database, and also directly convert a database into a relational chart.

Are schema and database the same?

When it comes to database schema, there are many doubts. The problem often arises whether there is a difference between schema and database, and if so, where is the difference.

It depends on the database vendor

Part of the confusion about schema is that database systems tend to handle schema in their own way

(1) MySQL documents point out that in physics, schema and database are synonymous, so schema and database are the same thing.

(2) However, Oracle documents point out that some objects can be stored in the database, but not in the schema. Therefore, schema and database are not the same thing.

(3) According to this SQL Server technical article, schema is an independent entity within SQL server. So, they are not the same thing.

Therefore, depending on the RDBMS you are using, the schema and database may not be the same.

How to define schema in SQL standard?

In ISO / IEC 9075-1 SQL standard, schema is defined as a persistent, named collection of descriptors. If you are confused about the definition of schema before, I hope it will be better, at least not worse after reading my article.

In a broad sense

Another reason for the confusion may be that the term schema has such a wide range of meanings, because it has different meanings in different environments. The word schema comes from the Greek SKH ē Ma, which means form, figure, shape or plan. In psychology, schema is used to describe the organized thinking or behavior patterns of organizational information categories and their relationships. Before we design a database, we also need to look at the types of information in the data and the relationship between them. Before we start to use the physical schema in DBMS, we need to create a conceptual schema. When discussing patterns in software development, we can discuss conceptual patterns, physical patterns, internal patterns, external patterns, logical patterns, etc., each of which has its own specific meaning.

Schema definition of DBMS

Here are the schema definitions of three leading relational database systems:

MySQL

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, theINFORMATION_ 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, aschema is synonymous with adatabase. You can substitute the keywordSCHEMA instead ofDATABASE 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, aschema represents only a part of a database: the tables and other objects owned by a single user.

MySQL official documents point out that conceptually, a schema is a set of interrelated database objects, such as tables, table columns, column data types, indexes, foreign keys, and so on. But from the physical level, schema and database are synonymous. You can use the keyword schema instead of database in the SQL syntax of MySQL, for example, create schema instead of create database .

Reference: MySQL glossary, MySQL 5.7 reference manual. Mysql, retrieved 6 June 2016.

SQL Server

The names of tables, fields, data types, and primary and foreign keys of a database.

SQL Server official documents point out that the schema contains the database table, field, data type and the name of primary key and foreign key. Reference: SQL Server glossary. SQL Server 2016 technical documentation. Microsoft developer network. Retrieved 6 June 2016

Oracle Database

The schema system in Oracle is very different from other database systems. The schema of Oracle is closely related to database users.

A schema is a collection of logical structures of data, or schema objects. A schema is owned by a database user and has the same name as that user. Each user owns a single schema.

Oracle official documents point out that schema is a collection of logical structures of data or schema objects, which is owned by database users and has the same name as the user, that is to say, each user has an independent schema.

Reference: Oracle database objects. Oracle database online documentation 12C release 1 (12.1). Oracle help center. Retrieved 6 June 2016

If you want to know more about schema, you can refer to this article schema definitions by DBMS

Create schema

Although the above three DBMS are different in defining schema, they all support create schema statements.

MySQL

In mysql, create schema creates a database because create schema is synonymous with create database . In other words, you can use create schema or create database to create a database.

Oracle Database

In Oracle, create schema statement does not actually create a schema, because a schema has been created for database users when creating users, that is to say, create user creates a schema in Oracle, create user creates a schema Schema statements allow you to associate schema with tables and views, and authorize them, so that you don’t have to issue multiple SQL statements in multiple transactions.

SQL Server

In SQL server, create schema creates a schema by name. Unlike mysql, the create schema statement creates a schema that is defined separately to the database. Different from Oracle, the create schema statement actually creates a schema (as mentioned earlier, this statement does not create a schema in Oracle). In SQL server, once the schema is created, users and objects can be added to the schema.

summary

The word schema can be used in many different environments. When creating a schema in a specific DBMS, you need to use the DBMS specific definition mode. When you switch to a new DBMS, you must check how the system defines the schema.

Read More: