Database relationship




FYI: https://docs.google.com/document/d/e/2PACX-1vSwbtuIFN5MEXNmQImTngRF80G8Sf3OMk5t-6nLWODXNRmMm7aOPHKVCzz-zghuWGWBuX_crKUMMk_P/pub

This paper deep into the fundamental of database relationships, providing an explanation of guidelines for completing a database diagram, an analysis of the anatomy of a database relationship, and an overview of the tools available to build database structures. 


1. Database relationship

In the realm of database management, relationships are very important for establishing connections between entities and helping the organization and retrieval of data become easier. There are different types of relationships commonly used in databases [1]:


  • One-to-One (1:1): One record in a table is related with only one record in another table. 

For example, in a fresh retail organization, every customer must have a unique account, and this relationship can be represented by a one-to-one relationship between the "Customer" table and the "Account" table.

Fig 1.1 One-to-One  relationship

  • One-to-Many (1:N): One record in a table can be related with multiple records in another table. 

For example, every customer can have multiple orders, which can be represented by a one-to-many relationship between the "Customer" table and the "Order" table.

Fig 1.2 One-to-Many  relationship

  • Many-to-Many (N:M): Multiple records in one table can be related with multiple records in another table. It requires the use of an intermediate table, known as a junction or linking table, to establish the relationship. 

For example, multiple customers can purchase multiple products, which can be represented by a many-to-many relationship between the "Customer" table and the "Product" table.

Fig 1.3 Many-to-Many  relationship


2. Completing a Database Diagram


A well-designed database diagram visualizes the structure of a database system and represents its entities, attributes, and relationships. Here are the general steps to complete a database diagram:

  • Identifying Entities: Begin by identifying the major entities in your database system. These entities represent the main objects or concepts that you want to store and manage data for. 

For example, in a fresh retail organization, entities could include "Customer," "Product," "Order," and "Account."



  • Defining Attributes: After identifying the entities, determine the attributes or properties of each entity that define the data that can be stored within each table. 

For example, attributes for the "Customer" entity might include "CustomerID," and "Name".


  • Determining Relationship Types: Determine the relationships between entities based on the requirements. 


For example, a customer can have multiple orders, indicating a one-to-many relationship between the "Customer" and "Order" entities. Identify and document the relationship types such as one-to-one, one-to-many, or many-to-many.


  • Assigning Primary Keys: Identify a primary key for each entity to ensure the uniqueness of records within that table. The primary key is a unique identifier for each record in the table. 

For example, "CustomerID" can be assigned as the primary key for the "Customer" table.


  • Adding Foreign Keys: To establish relationships between tables, foreign keys are used. Foreign keys are attributes in a table that refer to the primary key of another table. 


For example, the "Order" table may have a foreign key "CustomerID" that references the primary key "CustomerID" in the "Customer" table, connecting orders to their respective customers.

Fig 2. Completing a Database Diagram

3. Anatomy of a Database Relationship:

The anatomy of a database relationship consists of several key components such as:

Entities

Entities correspond to tables in the database and contain a collection of records

For example, in a customer-product relationship, "Customer" and "Product" are the entities.

Keys

Keys are used to uniquely identify records. Primary keys ensure record uniqueness, while foreign keys establish relationships between tables.

 For example, the primary key in the "Customer" entity is the "CustomerID" attribute. On the other hand, in the customer-product relationship, the "CustomerID" in the "Order" entity is a foreign key that references the primary key "CustomerID" in the "Customer" entity.

Relationship

The relationship indicates the relationship between entities. There are three popular relationship types: one-to-one, one-to-many, and many-to-many.

Cardinality

Cardinality is the number of records in one entity that can be related with the number of records in another entity. Cardinality can be one-to-one, one-to-many, or many-to-many. 

For example, in the customers-orders relationship, one customer can have multiple orders, but each order is related with only one customer.


4. Tools to Build Database Structures:

  • Entity-Relationship Diagram (ERD) tools:

Navicat , Draw.io, and Microsoft Visio provide visual design capabilities for creating and modifying database diagrams. While not specifically designed for database modeling, they provide features and templates that can be utilized to create entity-relationship diagrams and visualize database relationships.

  • Database management systems (DBMS): 

DBMS tools are software systems that manage relational databases. They provide a comprehensive set of features to design, create, and manage database relationships.

MySQL, PostgreSQL, Oracle, and Microsoft SQL Server offer comprehensive database management tools with design functionalities.



In conclusion, a well-designed database diagram is very important for visualizing the structure of a database system. The need of identifying entities, define attributes, determine relationship types, assign primary keys, and foreign keys, and determine the relationships among entities is very necessary  for ensuring the accuracy and integrity of the database system


Reference: 

[1] Database relationships. (2021, March 3). IBM. 

https://www.ibm.com/docs/en/control-desk/7.6.0?topic=SSWT9A_7.6.0/com.ibm.mbs.doc/configur/c_db_relationships.html


[2] Bagui, S., & Earp, R. (2011). Database design using entity-relationship diagrams.  Auerbach Publications. https://www.amazon.com/Database-Design-Entity-Relationship-Diagrams-Foundations/dp/1439861765


[3] Watt, A., & Eng, N. (2014). Chapter 13 Database Development Process. In Database design, 2nd Edition. Opentext. Licensed under CC BY 4.0.  https://opentextbc.ca/dbdesign01/


[4] Trust navicat for all your database management needs.cast your vote for us in the DBTA awards in four categories!. Retrieved from https://navicat.com/en


[5]  Fergusson, K. (2021). Entity relationship diagrams with Draw.io. Retrieved from https://drawio-app.com/blog/entity-relationship-diagrams-with-draw-io/


[6] Retrieved from https://support.microsoft.com/en-us/office/create-entity-relationship-diagrams-in-visio-7e44448c-9415-490b-8af1-f548f46ae90c


[7] Retrieved from https://www.mysql.com/

[8] Group, P. G. D. (2023). Retrieved from https://www.postgresql.org/

[9] Retrieved from https://www.microsoft.com/en-us/sql-server/sql-server-downloads

[10] Retrieved from https://www.oracle.com/corporate/


Post a Comment

Comment

Previous Post Next Post
WANG !!!!!
https://s.shopee.vn/609U3II1Xf