A database schema describes the structure and relationships of information in a database. It includes entities and tables, with primary and foreign keys used to express one-to-many relationships. Many-to-many relationships require special data modeling. There are standard conventions, but the design is up to the data modeler. Some DBMS systems can implement the design automatically.
A database schema is a way of describing the structure and relationships of information that will be used and maintained within a database. Some diagrams are written in a language that can be interpreted by database management software (DBMS), while others are completely abstract diagrams. The primary elements of a database schema are entities and tables. An entity is a data model for an object in a database, while a table is a stored sequence of values or other entities. Like a blueprint, a well-designed schema can be used to see exactly how a database architecture is built.
Sometimes database schemas are needed to explicitly show how data is stored and how it relates to the rest of the database. An entity is a representation of a collection of data. Like any data structure, it can have a number of fields. However, entities usually have a unique identification field. This is called the primary key.
A primary key is a link to a table. The key must be unique among all other table elements. An example would be a customer number for a database that tracks in-store purchases. Each entity can have only one primary key.
Entities can also have any number of foreign keys. A foreign key is often the primary key of another entity in another table. In the example above, a foreign key could be an order number for that customer.
In relational databases, primary and foreign keys are used to express the very important concept of one-to-many relationships. In the example given, a customer can have many different orders and order numbers. The reverse is not true, because the order can only have one customer. One-to-many relationships are part of why you need a database schema.
Another type of relationship is called many-to-many. This is an instance where an entity can not only have many relationships with a single type, but can also be included in many types by another type. An example of this is how any number of customers can order the same product. At the same time, a customer can order any number of products. This many-to-many relationship is common, but requires special data modeling to work within the database schema.
While there are some standard conventions that are followed when creating a database schema, there are also many ways to represent data models. Exactly how each schema object is represented in an abstract design is up to the data modeler. In some situations, a DBMS system will be able to accept a database schema written in a specific way and actually implement part of the design automatically.
Protect your devices with Threat Protection by NordVPN