The Wayback Machine - https://web.archive.org/web/20241127235748/https://www.geeksforgeeks.org/database-schemas/
Open In App

Database Schemas

Last Updated : 19 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Nowadays data is one of the most important things in the business world, every business captures its customers data to understand their behavior, in the world of the internet, data is growing like crazy, so businesses need more advanced database solutions by which they can maintain the database systems and whenever they need data to solve business problems, they can easily get what data they want without any problem. To fulfill this condition, there is a requirement for the database schema in the picture.

What is Schema?

  • The Skeleton of the database is created by the attributes and this skeleton is named Schema.
  • Schema mentions the logical constraints like table, primary key, etc.
  • The schema does not represent the data type of the attributes.

Details of a Customer

Details of a Customer

Schema of Customer

                                            Schema of Customer 

Database Schema

  • A database schema is a logical representation of data that shows how the data in a database should be stored logically. It shows how the data is organized and the relationship between the tables.
  • Database schema contains table, field, views and relation between different keys like primary key, foreign key.
  • Data are stored in the form of files which is unstructured in nature which makes accessing the data difficult. Thus to resolve the issue the data are organized in structured way with the help of database schema.
  • Database schema provides the organization of data and the relationship between the stored data.
  • Database schema defines a set of guidelines that control the database along with that it provides information about the way of accessing and modifying the data.

Types of Database Schemas

There are 3 types of database schema:

Physical Database Schema

  • A Physical schema defines, how the data or information is stored physically in the storage systems in the form of files & indices. This is the actual code or syntax needed to create the structure of a database, we can say that when we design a database at a physical level, it’s called physical schema.
  • The Database administrator chooses where and how to store the data in the different blocks of storage.

Logical Database Schema

  • A logical database schema defines all the logical constraints that need to be applied to the stored data, and also describes tables, views, entity relationships, and integrity constraints. 
  • The Logical schema describes how the data is stored in the form of tables & how the attributes of a table are connected.
  • Using ER modelling the relationship between the components of the data is maintained.
  • In logical schema different integrity constraints are defined in order to maintain the quality of insertion and update the data. 

View Database Schema

  • It is a view level design which is able to define the interaction between end-user and database.
  • User is able to interact with the database with the help of the interface without knowing much about the stored mechanism of data in database.
View Database Schema

Three Layer Schema Design

Creating Database Schema

For creating a schema, the statement “CREATE SCHEMA” is used in every database. But different databases have different meanings for this. Below we’ll be looking at some statements for creating a database schema in different database systems:

1. MySQL: In MySQL, we use the “CREATE SCHEMA” statement for creating the database, because, in MySQL CREATE SCHEMA and CREATE DATABASE, both statements are similar.

2. SQL Server: In SQL Server, we use the “CREATE SCHEMA” statement for creating a new schema.

3. Oracle Database: In Oracle Database, we use “CREATE USER” for creating a new schema, because in the Oracle database, a schema is already created with each database user. The statement “CREATE SCHEMA” does not create a schema, instead, it populates the schema with tables & views and also allows one to access those objects without needing multiple SQL statements for multiple transactions. 

Database Schema Designs

There are many ways to structure a database, and we should use the best-suited schema design for creating our database because ineffective schema designs are difficult to manage & consume extra memory and resources.

Schema design mostly depends on the application’s requirements. Here we have some effective schema designs to create our applications, let’s take a look at the schema designs:

  1. Flat Model
  2. Hierarchical Model
  3. Network Model
  4. Relational Model
  5. Star Schema
  6. Snowflake Schema

Flat Model

A flat model schema is a 2-D array in which every column contains the same type of data/information and the elements with rows are related to each other. It is just like a table or a spreadsheet. This schema is better for small applications that do not contain complex data.

Flat-model

Designing Flat Model

Hierarchical Model

Data is arranged using parent-child relationships and a tree-like structure in the Hierarchical Database Model. Because each record consists of several children and one parent, it can be used to illustrate one-to-many relationships in diagrams such as organizational charts. Although obvious, it might not be as adaptable in complicated partnerships.

Hierarchical Model

Designing Hierarchical Model

Network Model

The network model and the hierarchical model are quite similar with an important difference that is related to data relationships. The network model allows many-to-many relationships whereas hierarchical models allow one-to-many relationships.

Network Model

Designing Network Model

Relational Model

The relational model is mainly used for relational databases, where the data is stored as relations of the table. This relational model schema is better for object-oriented programming.

Relational model

Designing Relational Model

Star Schema

Star schema is better for storing and analyzing large amounts of data. It has a fact table at its center & multiple dimension tables connected to it just like a star, where the fact table contains the numerical data that run business processes and the dimension table contains data related to dimensions such as product, time, people, etc. or we can say, this table contains the description of the fact table. The star schema allows us to structure the data of RDBMS.

Star Schema

Designing Star Schema

Snowflake Schema

Just like star schema, the snowflake schema also has a fact table at its center and multiple dimension tables connected to it, but the main difference in both models is that in snowflake schema – dimension tables are further normalized into multiple related tables. The snowflake schema is used for analyzing large amounts of data.

Snowflake Schema

Designing Snowflake Schema

Difference between Logical and Physical Database Schema

Physical Schema

Logical Schema

Physical schema describes the way of storage of data in the disk.

Logical schema provides the conceptual view that defines the relationship between the data entities.

Having Low level of abstraction. Having a high level of abstraction.

The design of database is independent to any database management system.

The design of a database must work with a specific database management system or hardware platform.

Changes in Physical schema effects the logical schema Any changes made in logical schema have minimal effect in the physical schema
Physical schema does not include attributes. Logical schema includes attributes.
Physical schema contains the attributes and their data types. Logical schema does not contain any attributes or data types.
Examples: Data definition language(DDL), storage structures, indexes. Examples: Entity Relationship diagram, Unified Modeling Language, class diagram.

Advantages of Database Schema

  • Providing Consistency of data: Database schema ensures the data consistency and prevents the duplicates.
  • Maintaining Scalability: Well designed database schema helps in maintaining addition of new tables in database along with that it helps in handling large amounts of data in growing tables.
  • Performance Improvement: Database schema helps in faster data retrieval which is able to reduce operation time on the database tables.
  • Easy Maintenance: Database schema helps in maintaining the entire database without affecting the rest of the database
  • Security of Data: Database schema helps in storing the sensitive data and allows only authorized access to the database.

Database Instance

The database schema is defined before the actual database is created, after the database is operational, it is very difficult to modify the schema because the schema represents the fundamental structure of the database. Database instance does not hold any information related to the saved data in database. Therefore database instance represents the data and information that is currently stored in the database at a specific point in time.

Database Instance

Database instance of Customer table at a specific time

Database schema versus database instance

Aspect

Database Schema

Database Instance

Definition

Blueprint or design of the database structure

Actual data stored in the database at a given time

Nature

Static (does not change frequently)

Dynamic (changes with every data modification)

Represents

Structure (tables, columns, data types, relationships)

State of the data in the database

Example

Table definitions, data types, constraints

Actual rows of data in the tables

Change Frequency

Changes infrequently (e.g., during schema design changes)

Changes frequently with transactions

Conclusion

  • The Structure of the database is referred to as the Schema, and it represents logical restrictions like Table and Key, among other things.
  • Three Schema Architecture was developed to prevent the user from direct access to the database.
  • Since the information that is saved in the database is subject to frequent change, Instance is a representation of a data at a specific time.

FAQs

What is a database schema?

It is the blueprint or design for the actual database structure such as tables, columns, data types, and relationships.

What is a database instance?

A database instance consists of all the data actually stored at any point in time within a database.

How does a database instance differ from a database schema?

Schema: A structure comprising definition, static; instance: dynamic, representing the current state of the data.

Why is a database schema important?

It ensures the consistency, scalability, performance, maintenance, and security of the data.

Can the Schema of a Database Change Frequently?

No, changes in schema are infrequent, and this mostly happens in the processes of structural update or redesign.



Previous Article
Next Article

Similar Reads

How to Copy Database Schemas without Data in SQL Server
Copying database schemas without transferring data is a common requirement in database management, particularly when we need to replicate a database's structure across different environments or instances without the associated content. In SQL Server, a database schema comprises the organization of tables, views, stored procedures, and other objects
9 min read
How to Export Database and Table Schemas in SQLite?
Exporting database schemas in SQLite is an important task for database management, enabling functions like data backup, recovery, migration, and auditing. In this article, We will go through the process of exporting database and table schemas in SQLite by understanding various examples to manage SQLite databases effectively. How to Export Database
4 min read
Why does Mongose have Both Schemas and Models
In the world of MongoDB and Node.js, Mongoose is a popular object modeling tool that provides a straightforward way to interact with MongoDB databases. One of the key features of Mongoose is its use of schemas and models, which help define the structure of documents and provide an abstraction layer for performing database operations. In this articl
3 min read
How to Join two Schemas in Mongoose?
Mongoose is a popular MongoDB object modeling tool for Node.js that simplifies data manipulation. However, developers often face challenges when trying to join two schemas in Mongoose, as MongoDB, a NoSQL database, does not natively support join operations like SQL databases. In this article, We will learn about How to join two schemas in Mongoose
5 min read
How to List all Schemas in PostgreSQL?
In PostgreSQL, schemas are used to organize database objects such as tables, views, functions, and indexes into logical groups. Understanding how to list schemas within a PostgreSQL database is essential for effective database management, especially as databases grow in size and complexity. In this article, we will explain various methods to list a
4 min read
How to pre populate database in Android using SQLite Database
Introduction : Often, there is a need to initiate an Android app with an already existing database. This is called prepopulating a database. In this article, we will see how to pre-populate database in Android using SQLite Database. The database used in this example can be downloaded as Demo Database. To prepopulate a SQLite database in an Android
7 min read
Database Sharding Pattern for Scaling Microservices Database Architecture
Database sharding is an architectural technique that divides a large database into smaller and more manageable sections called shards. Each shard operates as an independent database that stores a subset of the overall data. Traditional monolithic database designs face many challenges to keep up with rapidly growing data volumes and the demands for
5 min read
Difference between Database Administrator and Database Architect
In the field of data management the position of a DBA and that of a Database Architect while sounding similar are in fact quite distinct. Although both jobs are crucial for maintaining the functionality and the protection of databases, both jobs engaged on various tasks connected with database management. A DBA is mainly involved in database admini
5 min read
Difference between Open Source Database and Commercial Database
Databases play a critical role in storing and managing structured data, with the help of a Database Management System (DBMS). They are broadly categorized into two types: open-source and commercial. Open-source databases, like MySQL and PostgreSQL, are freely available and allow customization, making them a popular choice for budget-conscious organ
6 min read
Difference between Database Administrator (DBA) and Database Engineer
Database Administrator is a user who is responsible for all duties related to the database like performance, optimization, backup, recovery, etc. Whereas the Data Engineer is the user who is responsible for developing the databases and he/she must ensure the proper functioning of the database. This article will provide an in-depth guide about the m
5 min read
Difference between Centralized Database and Distributed Database
As we know, databases are widely used for efficient storage, search, and other operations with data in the process of data management. Listening to the experience of using databases, two major categories are Centralized Databases and Distributed Databases. It is crucial to grasp the distinctions between these two types since every one of them posse
6 min read
Difference between Graph Database and Relational Database
Graph Databases and Relational Databases are essential. Each type has its strengths and weaknesses, which makes them suitable for different use cases. Graph Databases excel in representing complex relationships and connections among data points, making them ideal for applications like social networks. In this article, we will explain the key differ
4 min read
Database Management Systems | Set 3
Following Questions have been asked in GATE 2012 exam. 1) Consider the following transactions with data items P and Q initialized to zero: T1: read (P) ; read (Q) ; if P = 0 then Q : = Q + 1 ; write (Q) ; T2: read (Q) ; read (P) ; if Q = 0 then P : = P + 1 ; write (P) ; Any non-serial interleaving of T1 and T2 for concurrent execution leads to (A)
3 min read
Database Management Systems | Set 4
Following Questions have been asked in GATE 2011 exam. 1. Consider a relational table with a single record for each registered student with the following attributes. 1. Registration_Number:< Unique registration number for each registered student 2. UID: Unique Identity number, unique at the national level for each citizen 3. BankAccount_Number:
4 min read
Database Management Systems | Set 5
Following Questions have been asked in GATE CS 2010 exam. 1) A relational schema for a train reservation database is given below. Passenger (pid, pname, age) Reservation (pid, class, tid) Table: Passenger pid pname age ----------------- 0 Sachin 65 1 Rahul 66 2 Sourav 67 3 Anil 69 Table : Reservation pid class tid --------------- 0 AC 8200 1 AC 820
4 min read
Database Management Systems | Set 6
Following questions have been asked in GATE 2009 CS exam. 1) Consider two transactions T1 and T2, and four schedules S1, S2, S3, S4 of T1 and T2 as given below: T1 = R1[X] W1[X] W1[Y] T2 = R2[X] R2[Y] W2[Y] S1 = R1[X] R2[X] R2[Y] W1[X] W1[Y] W2[Y] S2 = R1[X] R2[X] R2[Y] W1[X] W2[Y] W1[Y] S3 = R1[X] W1[X] R2[X] W1[Y] R2[Y] W2[Y] S1 = R1[X] R2[Y]R2[X
4 min read
Database Management Systems | Set 7
Following questions have been asked in GATE 2008 CS exam. 1) Let R and S be two relations with the following schema R (P,Q,R1,R2,R3) S (P,Q,S1,S2) Where {P, Q} is the key for both schemas. Which of the following queries are equivalent? (A) Only I and II (B) Only I and III (C) Only I, II and III (D) Only I, III and IV Answer (D) In I, Ps from natura
3 min read
Database Management Systems | Set 10
Following questions have been asked in GATE CS 2005 exam. 1) Let r be a relation instance with schema R = (A, B, C, D). We define r1 = 'select A,B,C from r' and r2 = 'select A, D from r'. Let s = r1 * r2 where * denotes natural join. Given that the decomposition of r into r1 and r2 is lossy, which one of the following is TRUE? (a) s is subset of r
3 min read
Database Management Systems | Set 8
Following questions have been asked in GATE 2005 CS exam. 1) Which one of the following statements about normal forms is FALSE? (a) BCNF is stricter than 3NF (b) Lossless, dependency-preserving decomposition into 3NF is always possible (c) Lossless, dependency-preserving decomposition into BCNF is always possible (d) Any relation with two attribute
3 min read
Database Management Systems | Set 9
Following questions have been asked in GATE 2006 CS exam. 1) Consider the following log sequence of two transactions on a bank account, with initial balance 12000, that transfer 2000 to a mortgage payment and then apply a 5% interest. 1. T1 start 2. T1 B old=12000 new=10000 3. T1 M old=0 new=2000 4. T1 commit 5. T2 start 6. T2 B old=10000 new=10500
4 min read
Database Management Systems | Set 11
Following questions have been asked in GATE CS 2007 exam. 1) Information about a collection of students is given by the relation studinfo(studId, name, sex). The relation enroll(studId, courseId) gives which student has enrolled for (or taken) that course(s). Assume that every course is taken by at least one male and at least one female student. Wh
5 min read
PHP | MySQL Database Introduction
What is MySQL? MySQL is an open-source relational database management system (RDBMS). It is the most popular database system used with PHP. MySQL is developed, distributed, and supported by Oracle Corporation. The data in a MySQL database are stored in tables which consists of columns and rows.MySQL is a database system that runs on a server.MySQL
4 min read
PHP | MySQL ( Creating Database )
What is a database? Database is a collection of inter-related data which helps in efficient retrieval, insertion and deletion of data from database and organizes the data in the form of tables, views, schemas, reports etc. For Example, university database organizes the data about students, faculty, and admin staff etc. which helps in efficient retr
3 min read
Database Objects in DBMS
A database object is any defined object in a database that is used to store or reference data.Anything which we make from create command is known as Database Object.It can be used to hold and manipulate the data.Some of the examples of database objects are : view, sequence, indexes, etc. Table - Basic unit of storage; composed rows and columns View
4 min read
Challenges of database security in DBMS
Seeing the vast increase in volume and speed of threats to databases and many information assets, research efforts need to be consider to the following issues such as data quality, intellectual property rights, and database survivability. Let's discuss them one by one. 1. Data quality - The database community basically needs techniques and some org
5 min read
SQL Trigger | Book Management Database
Prerequisite - SQL Trigger | Student Database For example, given Library Book Management database schema with Student database schema. In these databases, if any student borrows a book from library then the count of that specified book should be decremented. To do so, Suppose the schema with some data, mysql> select * from book_det; +-----+-----
2 min read
Advantages of Distributed database
Distributed databases basically provide us the advantages of distributed computing to the database management domain. Basically, we can define a Distributed database as a collection of multiple interrelated databases distributed over a computer network and a distributed database management system as a software system that basically manages a distri
4 min read
Federated database management system issues
What is a Federated Database Management System? A Federated Database Management System (FDBMS) is a type of distributed database management system that allows users to access and manipulate data stored in multiple databases. It is a system that integrates data from different sources, providing a single view of the data to users. This type of system
9 min read
Data Management issues in Mobile database
Data management technology that can support easy data access from and to mobile devices is among the main concerns in mobile information systems. Mobile computing may be considered a variation of distributed computing. The two scenarios in which mobile databases is distributed are: Among the wired components, the entire database is distributed, pos
7 min read
Perl | Database management using DBI
Prerequisites: Introduction to Perl Database Systems Creating database programs is one of the most common uses of Perl. Using Perl, we can create robust web applications along with a database to manage all the data. It provides excellent support for interfacing and a broad range of database formats. For connecting to and querying a database, Perl p
7 min read
three90RightbarBannerImg