Database - rahul7838/quora.clone GitHub Wiki
Schema and Data Model
A database schema is the formal structure and organization of a database, defining:
Tables, columns, and their data types
Relationships between tables
Constraints (primary keys, foreign keys, unique constraints)
Views and indexes
- A database data model is a higher-level conceptual representation that:
Describes how data is organized, accessed, and related
Can be implemented through different schemas Examples include relational, hierarchical, network, and object-oriented models
Key differences:
Abstraction level: Data models are conceptual frameworks, while schemas are concrete implementations
Scope: Models define overall architecture; schemas specify detailed technical requirements
Purpose: Models guide database design; schemas enforce data structure and relationships
For example, a relational data model might be implemented through different SQL schemas depending on specific requirements and optimizations needed.
Different Data Model
A database data model is a theoretical framework that determines how data will be stored, organized, and manipulated. The key data models are:
Relational Model
Data organized in tables (relations)
Uses SQL
Example schema: Customer table linked to Orders table via foreign key
Hierarchical Model
Data organized in tree structure
Parent-child relationships
Example schema: XML database with nested elements
Network Model
Data organized in graph structure
Many-to-many relationships
Example schema: Flight routes database where cities connect to multiple other cities
Object-Oriented Model
Data organized as objects with attributes and methods
Inheritance and encapsulation
Example schema: Java objects stored directly in database
Each model can be implemented through different schemas based on specific needs. For example, a relational model for an e-commerce system could have different schemas:
Normalized schema (separate tables for products, categories, prices)
Denormalized schema (combined tables for faster querying)
Hybrid schema (mix of normalized and denormalized)