How should data be structured to support join operations in many to many relationships? Oracle sql plsql interview question for fresher and experienced.
Many to Many Relationships in join operations:
Joining tables or bridging tables are done on the basis of many to many relationships which are used to store records by every possible combination of records of both the tables. In order to handle many to many relationships is quite complex than one to one relationship and one to many relationships. It occurs when the multiple records in the table are related to the multiple records in another table. Students which are enrolling into the multiple courses are example of this type, which are part of the school or college database.
Understanding of this concept are useful for designing scalable and flexible databases. In order to fulfill the various application requirements, the complex data interaction is required. This concept is important in the relational database management system. Problems or challenges occurred like database schema becoming too complex or maintaining the performance on the consistent basis. In ecommerce platforms, it is extensively used. Single order can contain unique order id and contains the list of products. Each products available in the stock can be used in the multiple orders can have different order ids.Double joins is applied to the bridge tables for retrieving the elements.
Complexity may occur in the database schema design:
This concept can complicate the database schema design. Junction table is introduced to handle this issue which aid in adding another layer of complexity. Foreign key used in the junction table are correctly referenced with the primary key used in the related tables. Maintaining data integrity becomes quite challenging. Any changes like updation and deletion in the primary key table must be reflecting in the junction table in order to avoid data inconsistencies or orphaned records. Careful, well planning and time to time maintenance activities are required.
Performance Overhead:
It can bring out the performance overhead issue. Joins and queries are using the junction tables which are resource intensive and expands the data volume. Each join operation will slow down the query execution time. It requires the database to match rows from the related tables. Complex queries with multiple joins can cause increase in performance overhead. Due to evolving number of joins in the particular query can cause performance issue by passing load on the database server to retrieve the required and excepted results to bring out the slowness in the execution time.
Data redundancy:
Junction table can contain the duplicated data which leads to the increase in the storage requirements. Junction table contains the number of relationships increase between the two or more rows which cause increase in its size. Data management may become difficult task due to data redundancy. Duplicated data needs to be consistent across the database. If any changes made to the rows of the columns in the junction table can occur burden of maintenance.
Use of Junction tables:
It acts as intermediaries between the related entities which holds the foreign key of the one entity that reference the primary key of another entity. In order to retrieve the necessary data, you can perform the joins between the junction table and related tables. This can increase your schema design. If the two table names are student and marks respectively, then the junction table will be appearing as like student_marks.
Query Optimization:
It is useful for maintaining the performance. Indexing on the foreign key columns in the junction table can increase the speed of the query execution. When indexing is applied on the columns, you enable or allows the database to retrieve those records or rows which matches the required condition and reducing the time of the joins.Denormalisation can improve the performance by storing the redundant data by avoiding complex joins. Drawback of denormalization can lead to data inconsistency if it is not managed properly. Changes in one table must be reflecting in the multiple places which fulfill the application needs. Instead, normalized schema is preferred to store the redundant data in the single table by using the multiple tables and junction table.
No SQL Database:
It provides an alternative approach to handle this without the use of junction table. It is sub-divided into document oriented and graph databases.
Document oriented databases:
Comments
Post a Comment