架构、表和数据库之间有什么区别?

发布于 2024-07-08 09:29:25 字数 81 浏览 14 评论 0原文

这可能是一个n00blike(或更糟)的问题。 但我一直将模式视为数据库中的表定义。 这是错误的或者不完全正确的。 我对数据库课程的记忆不多。

This is probably a n00blike (or worse) question. But I've always viewed a schema as a table definition in a database. This is wrong or not entirely correct. I don't remember much from my database courses.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

穿越时光隧道 2024-07-15 09:29:25

架构 -> 平面图

数据库 -> 房子

桌子 -> 房间

schema -> floor plan

database -> house

table -> room

柠檬色的秋千 2024-07-15 09:29:25

关系模式是表的逻辑定义 - 它定义表的名称以及每列的名称和类型。 它就像一个计划或蓝图。 数据库模式是整个数据库的关系模式的集合。

是具有一堆行(也称为“元组”)的结构,每行都具有架构定义的属性。 表上还可能有索引,以帮助查找某些列上的值。

正式来说,数据库是任何数据的集合。 在这种情况下,数据库将是表的集合。 DBMS(数据库管理系统)是管理和运行数据库的软件(如 MySQL、SQL Server、Oracle 等)。

A relation schema is the logical definition of a table - it defines what the name of the table is, and what the name and type of each column is. It's like a plan or a blueprint. A database schema is the collection of relation schemas for a whole database.

A table is a structure with a bunch of rows (aka "tuples"), each of which has the attributes defined by the schema. Tables might also have indexes on them to aid in looking up values on certain columns.

A database is, formally, any collection of data. In this context, the database would be a collection of tables. A DBMS (Database Management System) is the software (like MySQL, SQL Server, Oracle, etc) that manages and runs a database.

亣腦蒛氧 2024-07-15 09:29:25

简而言之,模式是整个数据库的定义,因此它包括表、视图、存储过程、索引、主键和外键等。

In a nutshell, a schema is the definition for the entire database, so it includes tables, views, stored procedures, indexes, primary and foreign keys, etc.

沉默的熊 2024-07-15 09:29:25

模式的行为看起来就像 OOP 世界中的父对象。 所以它本身不是数据库。 也许此链接很有用。

但是,在 MySQL 中,两者是等效的。 关键字 DATABASE 或 DATABASES
无论出现在哪里,都可以用 SCHEMA 或 SCHEMAS 替换。 示例:

  • 创建数据库 <=> 创建模式
  • 显示数据库<=> 显示架构

MySQL 文档

数据库术语依赖于 DBMS。

表格是一组数据元素(值),使用垂直列(通过其名称标识)和水平行的模型进行组织。 数据库包含一个或多个(通常)。 您将数据存储在这些表中。 这些表可能彼此相关(参见此处)。

Schema behaves seem like a parent object as seen in OOP world. so it's not a database itself. maybe this link is useful.

But, In MySQL, the two are equivalent. The keyword DATABASE or DATABASES
can be replaced with SCHEMA or SCHEMAS wherever it appears. Examples:

  • CREATE DATABASE <=> CREATE SCHEMA
  • SHOW DATABASES <=> SHOW SCHEMAS

Documentation of MySQL

SCHEMA & DATABASE terms are something DBMS dependent.

A Table is a set of data elements (values) that is organized using a model of vertical columns (which are identified by their name) and horizontal rows. A database contains one or more(usually) Tables . And you store your data in these tables. The tables may be related with one another(See here).

无风消散 2024-07-15 09:29:25

该特定发布已被证明仅与 Oracle 相关,并且在另一个数据库上下文中时架构的定义会发生变化。

可能只是谷歌搜索一下,但仅供参考,术语的定义似乎有所不同,这是最烦人的事情:)

在 Oracle 中,数据库就是数据库。 在您的脑海中,将其视为数据文件和重做日志以及数据库本身(即不是实例)磁盘上的实际物理存在。

模式实际上是用户。 更具体地说,它是用户拥有的一组表/过程/索引等。 另一个用户具有不同的架构(他/她拥有的表),但是用户也可以查看他们拥有选择权限的任何架构。 因此,一个数据库可以包含数百个模式,每个模式包含数百个表。 您可以在同一数据库中的不同模式中拥有相同名称的表。

表是一个表,是包含数据的一组行和列,并且包含在模式中。

例如,SQL Server 中的定义可能有所不同。 我不知道这一点。

This particular posting has been shown to relate to Oracle only and the definition of Schema changes when in the context of another DB.

Probably the kinda thing to just google up but FYI terms do seem to vary in their definitions which is the most annoying thing :)

In Oracle a database is a database. In your head think of this as the data files and the redo logs and the actual physical presence on the disk of the database itself (i.e. not the instance)

A Schema is effectively a user. More specifically it's a set of tables/procs/indexes etc owned by a user. Another user has a different schema (tables he/she owns) however user can also see any schemas they have select priviliedges on. So a database can consist of hundreds of schemas, and each schema hundreds of tables. You can have tables with the same name in different schemas, which are in the same database.

A Table is a table, a set of rows and columns containing data and is contained in schemas.

Definitions may be different in SQL Server for instance. I'm not aware of this.

爱,才寂寞 2024-07-15 09:29:25

输入图像描述此处

根据 https://www.informit.com/文章/article.aspx?p=30669

所有对象的名称在一定范围内必须是唯一的。 每一个
数据库必须有唯一的名称; 模式的名称必须是唯一的
在单个数据库范围内,表名必须是
在单个模式的范围内是唯一的,并且列名必须是
表内唯一。 索引的名称在索引中必须是唯一的
数据库。

enter image description here

As per https://www.informit.com/articles/article.aspx?p=30669

The names of all objects must be unique within some scope. Every
database must have a unique name; the name of a schema must be unique
within the scope of a single database, the name of a table must be
unique within the scope of a single schema, and column names must be
unique within a table. The name of an index must be unique within a
database.

夜吻♂芭芘 2024-07-15 09:29:25

来自 PostgreSQL 文档

数据库包含一个或多个命名模式,而这些模式又包含表。 模式还包含其他类型的命名对象,包括数据类型、函数和运算符。 不同的schema可以使用相同的对象名,不会发生冲突; 例如,schema1myschema 都可以包含名为 mytable 的表。 与数据库不同,模式并不是严格分离的:用户可以访问他所连接的数据库中任何模式中的对象(如果他有权限的话)。

人们可能想要使用架构有几个原因:

  • 允许多个用户使用同一个数据库而不互相干扰。

  • 将数据库对象组织成逻辑组以使它们更易于管理。

  • 第三方应用程序可以放入单独的架构中,这样它们就不会与其他对象的名称发生冲突。

架构类似于操作系统级别的目录,但架构不能嵌套。

From the PostgreSQL documentation:

A database contains one or more named schemas, which in turn contain tables. Schemas also contain other kinds of named objects, including data types, functions, and operators. The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable. Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database he is connected to, if he has privileges to do so.

There are several reasons why one might want to use schemas:

  • To allow many users to use one database without interfering with each other.

  • To organize database objects into logical groups to make them more manageable.

  • Third-party applications can be put into separate schemas so they do not collide with the names of other objects.

Schemas are analogous to directories at the operating system level, except that schemas cannot be nested.

焚却相思 2024-07-15 09:29:25

与上面的一些答案相反,这是我根据每个答案的经验的理解:

  • MySQL: database/schema :: table
  • SQL Server: database :: (schema/namespace :: ) table
  • Oracle: database/schema/user :: (tablespace ::) table

请纠正我 Oracle 中表空间是否可选,我已经很久没有使用过他们。

Contrary to some of the above answers, here is my understanding based on experience with each of them:

  • MySQL: database/schema :: table
  • SQL Server: database :: (schema/namespace ::) table
  • Oracle: database/schema/user :: (tablespace ::) table

Please correct me on whether tablespace is optional or not with Oracle, it's been a long time since I remember using them.

宁愿没拥抱 2024-07-15 09:29:25

Schema 是数据库对象的集合,其中也包括逻辑结构。
它具有拥有它的用户的名称。
一个数据库可以有任意数量的模式。
数据库中的一张表可以出现在同名的两个不同模式中。
用户可以查看为其分配了选择权限的任何模式。

A Schema is a collection of database objects which includes logical structures too.
It has the name of the user who owns it.
A database can have any number of Schema's.
One table from a database can appear in two different schemas of same name.
A user can view any schema for which they have been assigned select privilege.

甜中书 2024-07-15 09:29:25

正如 MusiGenesis 在大多数数据库中所说的那样:

架构 : 数据库 : 表 :: 平面图 : 房子 : 房间

但是,在 Oracle 中可能更容易想到:

schema : 数据库 : 表 :: 所有者 : house : room

As MusiGenesis put so nicely, in most databases:

schema : database : table :: floor plan : house : room

But, in Oracle it may be easier to think of:

schema : database : table :: owner : house : room

白昼 2024-07-15 09:29:25

我尝试根据我对以下类比的理解来回答:

  • 数据库就像房子。
  • 房子里有几种类型的房间。 假设你住在一栋很大的房子里。 您确实不希望您的客厅、卧室、浴室、夹层、树屋等看起来都一样。 他们每个人都需要一个蓝图来告诉如何构建/使用它们。 换句话说,例如,他们每个人都需要一个模式来告诉如何建造/使用浴室。
  • 当然,您可能有几间卧室,每间卧室看起来都略有不同。 您和您妻子/丈夫的卧室与您孩子的卧室略有不同。 每间卧室都类似于数据库中的一张表格
  • DBMS 就像房子里的管家。 他几乎管理一切。

I try answering based on my understanding of the following analogy:

  • A database is like the house
  • In the house there are several types of rooms. Assuming that you're living in a really big house. You really don't want your living rooms, bedrooms, bathrooms, mezzanines, treehouses, etc. to look the same. They each need a blueprint to tell how to build/use them. In other words, they each need a schema to tell how to build/use a bathroom, for example.
  • Of course, you may have several bedrooms, each looks slightly different. You and your wife/husband's bedroom is slightly different from your kids' bedroom. Each bedroom is analogous to a table in your database.
  • A DBMS is like a butler in the house. He manages literally everything.
奢欲 2024-07-15 09:29:25

有关架构的更多信息:

在 SQL 2005 中,架构是一种对对象进行分组的方法。 它是一个可以放入物体的容器。 人们可以拥有这个物体。 您可以授予架构权限。

在 2000 年,模式相当于用户。 现在它已经摆脱束缚并且非常有用。 您可以将所有用户进程放入某个模式中,并将管理进程放入另一个模式中。 将 EXECUTE 授予适当的用户/角色,您就完成了对特定过程授予 EXECUTE 的操作。 好的。

点符号如下所示:

Server.Database.Schema.Object

myserver01.Adventureworks.Accounting.Beans

More on schemas:

In SQL 2005 a schema is a way to group objects. It is a container you can put objects into. People can own this object. You can grant rights on the schema.

In 2000 a schema was equivalent to a user. Now it has broken free and is quite useful. You could throw all your user procs in a certain schema and your admin procs in another. Grant EXECUTE to the appropriate user/role and you're through with granting EXECUTE on specific procedures. Nice.

The dot notation would go like this:

Server.Database.Schema.Object

or

myserver01.Adventureworks.Accounting.Beans

榕城若虚 2024-07-15 09:29:25

我喜欢与普遍理解的术语进行比较的公认答案。 但这让我有点困惑。 这是我的更新版本:
从存储/内存的角度来看,它们的关系:

Database (complete house) >>> schema (one room) >>> table (one closet in the room)

数据库:一栋完整的房子。 没有副本。

架构:一个特定的房间。 房子(数据库)中可以有很多房间(模式)

表:房间内的储藏室或桌子。 一个房间里可以有很多张桌子。

从还原技术来理解它:

删除数据库:摧毁整个房屋(从计算机中永久删除)。 此后,房子(数据库)的任何部分都不再保留。

删除架构:删除房间的所有内容。 还有其他带有内容的房间(带有存储数据的其他模式)

删除表:删除整个房屋(数据库)的房间(模式)内壁橱或桌子的内容。 因此,在这个房间(架构)中,还有其他桌子、壁橱,里面存储着物品。

I liked the accepted answer of comparing to a generally understood terminology. But it was a bit confusing to me. Here is my updated version of them:
Their relation from the storage/memory perspective:

Database (complete house) >>> schema (one room) >>> table (one closet in the room)

Database: One complete house. No copies.

schema: One specific room. There can be many rooms (schemas) in the house (database)

table: A storage closet or table inside a room. There can be many tables in a room.

Understanding it from the reduction technique:

Deleting a database: Razing down complete house (deleting from a computer permanently). No part of the house (database) remains after that.

Deleting a schema: Removing all contents of a room. There are other rooms with contents (other schemas with stored data)

Deleting a table: Removing contents of a closet or table inside a room (schema) of the complete house (database). So, in this room (schema), there are other tables, closet with contents stored in them.

月寒剑心 2024-07-15 09:29:25

在oracle中Schema是一个数据库下的一个用户,例如scott就是数据库orcl中的一个schema。
在一个数据库中,我们可能有许多模式,例如 scott

In oracle Schema is one user under one database,For example scott is one schema in database orcl.
In one database we may have many schema's like scott

叶落知秋 2024-07-15 09:29:25

模式包含数据库。

数据库是架构的一部分。

所以,模式> 数据库。

模式包含视图、存储过程、数据库、触发器等。

Schemas contains Databases.

Databases are part of a Schema.

So, schemas > databases.

Schemas contains views, stored procedure(s), database(s), trigger(s) etc.

饮惑 2024-07-15 09:29:25

模式并不是整个数据库的计划。 它是数据库内对象子集(例如表)的计划/容器。

这就是说,您可以在一个数据库中拥有多个对象(例如表),这些对象不一定属于同一功能类别。 因此,您可以将它们分组到不同的架构下,并授予它们不同的用户访问权限。

也就是说,我不确定是否可以在多个模式下拥有一张表。 Management Studio UI 提供了一个下拉列表,用于将架构分配给表,因此可以仅选择一个架构。 我想如果您使用 TSQL 执行此操作,它可能会创建 2 个(或多个)具有不同对象 ID 的不同对象。

A schema is not a plan for the entire database. It is a plan/container for a subset of objects (ex.tables) inside a a database.

This goes to say that you can have multiple objects(ex. tables) inside one database which don't neccessarily fall under the same functional category. So you can group them under various schemas and give them different user access permissions.

That said, I am unsure whether you can have one table under multiple schemas. The Management Studio UI gives a dropdown to assign a schema to a table, and hence making it possible to choose only one schema. I guess if you do it with TSQL, it might create 2 (or multiple) different objects with different object Ids.

半仙 2024-07-15 09:29:25

数据库架构是一种对表、视图、存储过程等对象进行逻辑分组的方法。将架构视为对象的容器。
表格是行和列的集合。
所有表的组合构成一个数据库。

A database schema is a way to logically group objects such as tables, views, stored procedures etc. Think of a schema as a container of objects.
And tables are collections of rows and columns.
combination of all tables makes a db.

离鸿 2024-07-15 09:29:25

好吧,其中一些你已经知道了。 数据库保存数据,但架构告诉您如何存储数据。 物理上的等价物可能是database:schema::warehouse:shelves。 也许书架也是按部分组织的(就像图书馆一样)。

模式基本上是如何构建数据库:

  • 数据库中应该有什么样的“模式对象”?
  • 它们应该被称为什么?
  • 它们应该具有什么“type”价值?

表是一种“模式对象”。 其他包括视图、操作符、存储函数、用户、角色、目录(这些可以细分,但为了基本理解不用担心)。

Okay, some of this you already know. The database holds the data, but the schema tells you how to store it. The physical equivalent might be database:schema::warehouse:shelves. Maybe the shelves are also organized by sections (like a library).

The schema is basically how to structure the database:

  • What kind of "schema objects" should be in the database?
  • What should they be called
  • What "type" of value should they have?

A table is one kind of "schema object." Others include views, operators, stored functions, users, roles, directories (these can be sub-divided, but don't worry about that for the basic understanding).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文