Oracle database tables and table columns to explain

If you compare a database to a locker that stores things, a table is like each drawer on the locker. Each drawer stores various data in different categories. When designing and planning a database, the definition and planning of tables are often very important , Good table design determines the convenience of programmers to write programs and the overall performance of the database. Now let's talk about the guidelines for understanding the structure and design of tables in Oracle.

1. Tables and entities

The concept of entity has been introduced. Entities are abstractions of the real world. When designing a database, you first need to consider the entities that the database needs to involve. For example, a warehouse database. If you divide the real world entities, you can have the following entities:

  • Warehouse, store the warehouse name and location.
  • Warehouse administrator, store and manage personnel information of warehouse, such as job number, name, age, etc.
  • Warehouse category, the type of storage warehouse, such as finished product warehouse, semi-finished product warehouse or raw material warehouse.
  • Location, store the location information of the items in the warehouse, such as location and structure of the location.

When designing and planning the structure of a table, you should distinguish objective things from the perspective of the real world, divide them into entities, and then plan the relationship between each entity, that is to say, generally draw the middle entity relationship (ER) diagram, This process is called "database modeling". With the entity relationship diagram, the database administrator can create the table. Taking the warehouse manager in the warehouse administrator as an example, the receipt returns the entity shown in Figure 1.1.


In the figure, the rectangle represents the entity, the ellipse represents the attribute of the entity, and the diamond represents the relationship between the entity. The relational database management system converts the entity into a two-dimensional table with a two-dimensional structure. The table is composed of table rows and table columns. Table columns carry attributes in table entities, while table rows are used to store specific values ​​of entity attributes. The structure of a database table is usually shown in Table 1.1.


It can be seen that the process of converting an entity to a table is the process of converting a two-dimensional table. The entire table is composed of table rows and table columns. Table columns store the attributes of the entity. Multiple table columns form the entity storage structure of the table. Generally When referring to the structure of a table, it is actually the composition of the table columns. The table rows store specific data according to the definition of table columns to form a specific table storage structure.

When converting an entity into a table, it is generally recommended to proceed through 3 steps:

(1) Define the attributes in the entity as table columns, and specify different database types for the table columns according to the different properties of the attributes. For example, names generally store character-type data, and age generally stores data-type data.

(2) Add constraints to the table based on the entity attributes and relationships in the ER relationship diagram. For example, the name is unique, name can add a primary key constraint; if you must specify a gender, you can add a non-null constraint; the relationship between the table and the table can be specified through foreign key constraints.

(3) After defining the table and table columns, add table rows according to the table columns to realize a data table with a two-dimensional structure.

When designing tables and table columns, you must conform to the database paradigm design introduced earlier. Therefore, the design of the table is also a process of returning to the iteration. It requires the designer in the data to carry out many iterations to achieve the optimal structure of the database.

Guess you like

Origin www.cnblogs.com/XXXHui/p/12673933.html