0% found this document useful (0 votes)
12 views

Intro_to_DBMS 1

Uploaded by

Kush Thakkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Intro_to_DBMS 1

Uploaded by

Kush Thakkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 95

Introduction

to DBMS
What is Data?

Data: Unprocessed fact


Information: Processed data

In SQL if we talk about data, it means we are referring to processed data


What Is a Database?

Database is anything that collects and organizes data (collection of related data)

(random data cannot be considered as a database)


A database holds one or more tables that may have relationships to each other. (hence also known as
Relational DBMS)
What is MetaData?
Complete description of database/defines database

What Is a Database Management System?

Database + Management System


A database management system (DBMS) is a set of programs/software to access, store and manage
data.
Classification of DBMS
The most widely used types of DBMS software are

• Relational
• Distributed
• Hierarchical
• Object-oriented and
• Network.
What is a Table?

Table stores data in row and column format and makes it easy for people to use the data.

Columns/Variables/features/attributes

Student_id First_Name Last_Name


101 Rahul Sharma
Rows/Records/observation 102 Venky Kumar
103 Richa Hegde
104 Sumit

Let's Jump to MySQL and create a basic table


create database BBA;
(show databases/tables)
Use BBA;
create table Students(
Student_id integer,
Student_name varchar(30)
);
Do you see a problem???
insert into Students values (1,"Rakesh");
insert into Students values (2,"Raju");
insert into Students values (3,"James");
insert into Students values (3,“Shilpa");

select * from Students;

Primary Key!!

Is a column/columns that uniquely identify each row in a table


Let's drop the students table and create it again!

drop table Students;

Recreate the table but now with a primary key constraint

create database BBA;


Use BBA;
create table Students(
Student_id integer primary key,
Student_name varchar(30)
);

insert into Students values (1,"Rakesh");


insert into Students values (2,"Raju");
insert into Students values (3,"James");
insert into Students values (3,“Shilpa");

select * from Students;


Desc Students;
Primary key

❑ The primary key is limited to a single table.

❑ It uniquely identify the corresponding rows of a table.

❑ A Primary key is a unique column we set in a table to easily identify and locate data in queries.

❑ A table can have only one primary key.​

❑ The primary key column has a unique value and doesn’t store repeating values. A Primary key
can never take NULL values.​
Data Types in SQL

Strings Varchar: A VARIABLE length string (can contain letters, numbers, and special characters) 0 to 65535
Char: A FIXED length string (can contain letters, numbers, and special characters)..0 to 255, default is 1

Numeric Integers, Float

Date& timestamp

https://paiza.io/en/languages/mysql
What is SQL?

o SQL is the standard database language used by almost every


Relational Database Management System (RDMS) such as
MySQL, MS Access, Oracle, Postgres, and SQL Server.
o SQL (Structured Query Language)
o It is a computer language used to store, manipulate, and
retrieve data from a relational database.

Characteristics of SQL
7. Best Suited for the Client-Server Environment
1. Easy to learn
8. Integration
2. Wide Variety of Commands 9. High performance
3. Stored Procedures 10. Scalability and Flexibility
4. Portable Language 11. Transactions
5. Joins 12. Security
6. Union
Database Languages Wide Variety of Commands

DDL: Data Definition Language (deals with structure of the table)


e.g create, drop, alter, Truncate

DML: Data Manipulation Language (deals with data of the table)


e.g Insert, update, delete,

DCL: Data Control Language (deals with the access control )


e.g grant, revoke

TCL: Transaction Control Language (deals with managing and controlling


transactions in a DB)
e.g commit, rollback, savepoint
DQL: Data Query Language (deals with retrieval of data)
e.g select
DBMS vs file-processing systems

Flat Files

• A flat file allows access to single files or tables at a time.

• In a File System, data is directly stored in a set of files.

• It contains flat files that have no relation to other files (when only one table is
stored in a single file, then this file is known as a flat file).

Example: The data that we store in our personal laptops in folders/sub folders etc. uses
FILE SYSTEM ( a way of storing data)
Advantages of DBMS over File system: Fast and Esay to Operate

Data integrity: DBMS uses constraints to attain data integrity

Data concurrency: Multiple users can access data at a time in a DBMS.

Data security: In DBMS we can provide Role based access (based on job level etc.) or read/Write etc.

Data Redundancy: Duplicacy of data is not allowed in DBMS as we have constraints for this.

Data Inconsistency: When we restrict duplicate entries, we will automatically protect data from inconsistency

Data location: We do not need to know the location of data/file to fetch/access it in DBMS.
• Data Model

Categories of Data Model


- Underlying structure of a database
- Conceptual tool
- Data+ relationship + semantics + constraints

1. Relational Model
2. Entity Relationship Model
3. Object-based Model
4. Semi-structured Data Model
Collection of tables

Tables represent both data and relationships

Multiple columns with unique names.

Relational Tables=Relations

Model Record based model

Each record type defines a fixed number of fields or attributes

Most widely used data model

Current DBS are based on relational model.


Relational Databases
RDBMS comprise of database that holds one or more tables that may have relationships to each
other
Relation: Combination of rows and column (Table)
Tuple (a particular entry in your table (row)

ORDER table

CUSTOMER table
Why Separate Tables?

Normalization!!!

• A technique of organizing the data in the database.


• Systematic approach of decomposing tables to eliminate data redundancy.
• Multi-step process that puts data into tabular form removing the duplicated data from its related tables.

Non-Normalized table
ORDER table

CUSTOMER table

Foreign key constraint


A FK is a field in one table (child table) that refers to the primary key in another table (parent table).
We can have as many Foreign keys as we want.
A foreign key comes to use when we need to link tables to one another and have data spread over
multiple table
Constraints are used to limit
the type of data that can go
into a table.

This ensures and maintains the


Constraints reliability and accuracy of the
data.

In case of any violation the


action gets aborted.
Primary key
❑ The primary key is limited to a single table.

❑ It uniquely identify the corresponding rows of a table.

❑ A Primary key is a unique column we set in a table to easily identify and locate data in queries.

❑ A table can have only one primary key.​

❑ The primary key column has a unique value and doesn’t store repeating values. A Primary key
can never take NULL values.​

FOREIGN KEY

❑ A FK is a field in one table (child table) that refers to the primary key in another table (parent
table).

❑ We can have as many Foreign keys as we want.

❑ A foreign key comes to use when we need to link tables to one another and have data spread
over multiple table
• UNIQUE KEY
• We can have multiple unique keys
• We can have unique keys on different columns
• The purpose of unique key is to make sure the values do
not duplicate.

• NOT NULL
• In SQL, null or NULL is a special marker used to indicate that a
data value does not exist in the database. Introduced by the
creator of the relational database model
• A NULL value is different from a zero value or a field that contains
spaces. A field with a NULL value is one that has been left blank
during record creation

• CHECK
• The CHECK constraint is used to limit the value range that can be
placed in a column.

Let's create Tables using these constraints...


Minimal subset of superkeys
• Data Model

Categories of Data Model


- Underlying structure of a database
- Conceptual tool
- Data+ relationship + semantics + constraints

1. Relational Model
2. Entity Relationship Model
3. Object-based Model
4. Semi-structured Data Model
Entity Relationship Model

Schematic/Diagrammatic
Collection of basic
E-R Data Model or ER An entity is a real world Distinguishable from Widely used in database representation so that
objects called entities
Model thing or object. other objects. design. this can be used in
and its relationship.
designing database

Entity

Attribute

Relationship Let's see how we get ER


model from database....
• If the icon is a small key, that column
belongs to the primary key
• A red diamond indicates a Foreign
Key association.

• Blue Diamond (Filled) = indicates NOT NULL


• Blue Diamond (unfilled) = indicates NULL
• Red Diamond, et cetera = indicates a foreign
key {filled: NOT NULL, unfilled: NULL}
Complex
Primary key
Degrees

Multivalued attributes
Employee

Schema: Logical Representation of Database

(The overall design of the database is called


database schema)
Each entity is involved in the relationship

Not all entities are involved in the relationship


Symbols and notations used in ER Diagram
• Identify roles of the given
shapes in an ER diagram.

Derived
attribute
• Weak entity
Q. Construct an ER
diagram with a hospital,
set of patients and a set
of doctors.
Enhanced ER
Diagram (Advanced
DBMS)
• Subclasses and Super
classes (subclass inherits
attributes of superclass)
• Generalization and
specialization
• Disjoint and overlapping
constraints
• Hierarchy and lattice
• Total and partial
participation
While designing if top to While designing if bottom
down model approach is to top approach is used it is
used it is known as known as generalization.
specialization.
Three level architecture( Abstraction)/Data Independence
DBMS
Architecture/Component/Structure
• What Is an SQL operator?

• An operator is a reserved word or a character


that is used to query our database in a SQL
expression.

• To query a database using operators, we use a


WHERE clause

• Operators are necessary to define a condition in


SQL, as they act as a connector between two or
more conditions.

• The operator manipulates the data and gives the


result based on the operator’s functionality.
What Are the Types of SQL Operators?

Generally, there are three types of


operators that are used in SQL.

• Arithmetic Operators
• Comparison Operators
• Logical Operators
Arithmetic SQL
Operators
• Arithmetic operators are
used to perform arithmetic
operations such as
addition, subtraction,
division, and multiplication.
• These operators usually
accept numeric operands.
• Different operators that
come under this category
are given below-
• Comparison SQL Operators

• Used to check the equality of two


expressions.
• It checks whether one expression is
identical to another.
• Generally used in the WHERE clause of a
SQL query.
• The result of a comparison operation may
be TRUE, FALSE or UNKNOWN.
• When one or both the expression is NULL,
then the operator returns UNKNOWN.
• These operators could be used on all types
of expressions except expressions that
contain a text or an image.
Logical SQL Operators

•Operators that take two expressions as


operands and return TRUE or False as output.

•While working with complex SQL statements


and queries, comparison operators come in
handy and these operators work in the same
way as logic gates do.
What is an information system?

An information system is made up of five components: hardware, software, data, people, and process.
System Development Life Cycle (SDLC)

All information systems projects have to


go through the four phases of planning,
analysis, design, and
implementation. These phases are part
of the system development life cycle
(SDLC). An important concept of SDLC is
this is an iterative process and the aim of
SDLC is to create a high quality system
that matches the customer
requirements regarding time, cost,
effectiveness and efficiency
• SDLC is a collection of processes
which are followed to develop a
software
Planning Stage
• The phase in which developers will plan for the upcoming project.

• It defines the problem

• Scope of any existing systems

• It determine the objectives for their new systems.

• Catch problems before they affect development.

• Help to secure the funding and resources

• The planning stage sets the project schedule


Analysis Stage

• Gathering all the specific details


• Determining the first ideas
for prototypes
• Developers may:
Define any prototype system
requirements
Evaluate alternatives to existing
prototypes
Perform research and analysis to
determine the needs of end-users

Developers will often create a software requirement


specification or SRS document.
Design Stage

Developers turn the SRS document they created into a more logical structure
that can later be implemented in a programming language

Development Stage
Developers actually write code and build the application according to the
earlier design documents and outlined specifications.
Testing Stage

Building software is not the end.

During the testing stage, developers will go over their software with a fine-tooth comb, noting
any bugs or defects that need to be tracked, fixed, and later retested.
After testing, the overall design for the software will
come together.

Different modules or designs will be integrated into


the primary source code through developer efforts,
Implementation usually by leveraging training environments to
detect further errors or defects.
and Integration
Stage The information system will be integrated into its
environment and eventually installed.

After passing this stage, the software is theoretically


ready for market and may be provided to any end-
users.
Maintenance Stage
• The SDLC doesn’t end when software reaches the
market.
• Developers must now move into a maintenance mode
and begin practicing any activities required to handle
issues reported by end-users.
• Developers are responsible for implementing any
changes that the software might need after deployment.
• This can include handling residual bugs that were not
able to be patched before launch or resolving new issues
that crop up due to user reports.
• Larger systems may require longer maintenance stages
compared to smaller systems.
Queries
To design an E-R (Entity-Relationship) diagram for keeping track of the exploits of your favorite sports team, you
can consider the following entities and their relationships:

1.Team: Represents the sports team.

•Attributes: TeamID (primary key), TeamName, TeamLocation, TeamLogo, etc.

2.Match: Represents the matches played by the team.

•Attributes: MatchID (primary key), MatchDate, MatchLocation, etc.

3.Player: Represents the players in each match.

•Attributes: PlayerID (primary key), PlayerName, PlayerPosition, etc.

4.MatchPlayer: Represents the relationship between matches and players.

•Attributes: MatchID (foreign key referencing Match), PlayerID (foreign key referencing Player), etc.
5.Score: Represents the scores in each match.

•Attributes: ScoreID (primary key), MatchID (foreign key referencing Match), TeamScore, OpponentScore,
etc.

6.PlayerStatistics: Represents individual player statistics for each match.

•Attributes: StatID (primary key), MatchID (foreign key referencing Match), PlayerID (foreign key referencing
Player), GoalsScored, Assists, YellowCards, RedCards, etc.

7.SummaryStatistics: Represents summary statistics derived from matches and player statistics.

•Attributes: SummaryID (primary key), TeamID (foreign key referencing Team), TotalMatchesPlayed,
TotalWins, TotalLosses, TotalGoalsScored, etc.
The relationships between these entities can be represented as
follows:

You might also like