Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Database (Lecture)

The document discusses databases and database management systems. It defines key concepts like data, information, files, records, fields, tables, and relationships. It also describes different types of databases and database models including relational, object-oriented, and distributed. Common operations on databases like select, insert, update and delete are explained.

Uploaded by

muhabdull30
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Database (Lecture)

The document discusses databases and database management systems. It defines key concepts like data, information, files, records, fields, tables, and relationships. It also describes different types of databases and database models including relational, object-oriented, and distributed. Common operations on databases like select, insert, update and delete are explained.

Uploaded by

muhabdull30
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

IICT

DataBase Lecture
Data and Information
• Data: Data is refers to the facts and figures in raw form. i.e not in
organized form.
For example item code, quantity and price of items purchased in a store
are data. When this data is entered into the computer and processed, it
prints the bill which is the output of the computer, also called the
information.
• Information: information is the processed or organized form of data.
Meaningful data is information.
File System Approach

File based systems were an early attempt to computerize the manual system. It is also
called a traditional based approach in which a decentralized approach was taken
where each department stored and controlled its own data with the help of a data
processing specialist.
Traditional File Processing
-Data stored in independent files

Problems:
• Data redundancy • Data inconsistency • Lack of data integrity • or standardization.
Database approach
A database approach is a well-organized collection of data that are
related in a meaningful way which can be accessed by different users
but stored only once in a system.
Oracle, SQL Server, Sybase etc.
Problems in File Management System
• In File Management System, records in one file system are not related
to the records in any other file. This approach leads to many problems,
which include data duplication in different files, data inconsistency, non-
sharing of data and lack of flexibility in organizing and querying the
data.
Example: A company may store a salesman’s name ,address telephone
number and commission rate in a file in Accounts Department and the
same information may be stored in another file in sales department . The
Account’s department for example may change the commission rate of
salesman but the sales department may fail to update its file. This will
produce reports calculated with out of data figures(Wrong data). The
inconsistency in files occurred due to duplication of same data in files.
This is the main problem faced in file Management systems.
Solution of the problem occur in File
Management:
• To solve the problem occur in traditional file the concept of a
Database was introduced.
Data base approach to Manage Files
• A database is a collection of related files.
• A database Management System is a set of programs that allow users
to create, maintain and manipulate and store database .
Functions of DBMS
– Retrieving Data, Editing. Adding, deleting
– Storing, Distributing Data and Organizing Data
DBMS

Reason for using databases


– Required in nearly every business – Can automate tasks and
Increases business efficiency – Commercial websites use databases i.e
online stores.
Example of DBMS include Microsoft Access, Microsoft SQL Sever,
Sybase, Oracle, MySQL etc.
Applications of Database Management System

Database Management System (DBMS) is used in various sectors with


applications like :
Banking: for storing customer information, account activities, deposits,
payment details, loans, etc.
Manufacturing: for supply chain management, production tracking and
inventory management
Finance: for storing information about stocks, sales, and purchases of
financial instruments like stocks and bonds
Universities: for student information, course registrations, payroll and grades
Airlines: for reservations, ticket booking and schedule information
Types of Databases
Enterprise Database: Large multiuser database systems developed and
maintained by IT professionals.
• Personal Database (PC Database): Typically reside on personal
computers and are designed to support a particular function.
• Microsoft Access is the most popular
• Microsoft SQL Server: Only runs on Microsoft platforms. Eight
different versions exist
• MySQL: Leading DBMS for Linux * Very inexpensive *Features are
needed in business
• Oracle: Most popular enterprise-level DBMS: Platform independent
• DB2: Venerable IBM database .Platform independent
Types of Databases
Distributed Database: A database stored on multiple machines. DBMS
will mask this organizational detail from its users.
These database systems are connected via communication links.

• Database model: A conceptual view of a database


– Relational database model
– Object-oriented database model
Object-oriented Databases
A database constructed by applying the object-oriented paradigm
• Each entity stored as a object.
• The data is represented and stored as objects which are similar to the objects used in
the object-oriented programming language.
• Object are used in object oriented programming languages such as C++,C# and Java.
Advantages of Object-oriented Databases
• Improved performance – improved performance in the case of object based
applications.
• Reusability – the code can be reused.
• Extensibility – Support for new data types - Unlike traditional DBMS products where
the basic data types are hard-coded in the DBMS .
• Enhanced modeling capabilities – it is easy to model the real-world object as close as
possible like the case of Object Oriented Programming concepts.
Relational Database:
A database in which the data are structured in a table format consisting
of rows and columns.
• Relation: A rectangular table
• Attribute(Fields): A column in the table
• Tuple(Record): A row in the table
Relational Database Model
• In a Relational Database Model the tables are linked by common
fields.
• The “relation” in a database refers to the various tables in the
database which are linked with each other.
• A table in database consist of rows and columns.
• One row of table holds one record.
• Each column in the table holds one field or attribute.
• Relational Database Model is more popular database in business
applications.
Relational Database Model
• Primary Key: Each entity in a database must have a unique key field
known as Primary key to identify a record. For example Roll number
of a student can be used as primary key in a student database.
• Foreign key: A key field used in a relationship between tables whose
value matches a primary key in other table is known as foreign key.
Example suppose we have two table in database one is student table
and other is Result table. Roll number is the primary key in student
table when it is used in Result table it is act as a foreign key.
Student Information Table
Roll number Std Name Department Semester Address
CS-123 Ali Computers 1 Axy-133
CS-233 Mustafa Computer 1 DDf-55
AI-777 Bina AI 1 KK-543
AI-443 Ali AI 1 MM-22
CS-311 Yasir Computer 2 Axy-133
Figure 9.3 A relation containing employee
information
Data Bases:
How to make a computerized Database
• Creating tables
– List the necessary fields
– Steps to define a field
• Specify field name, field type and field size.
• Create Forms
– Used to input and display the Data.
• Entering data into a table
– Users type data into a field or Forms.
• Reports (MIS/IS)
– Viewing records
– Produce printed results from the database
What is SQL(Structured Query Language)
• SQL is used to perform operations on the records stored in the
database, such as updating records, inserting records, deleting
records, creating and modifying database tables.
• SQL is not a database system, but it is a query language.
• Suppose you want to perform the queries of SQL language on the
stored data in the database. You are required to install any database
management system in your systems, for example, Oracle, MySQL,
MongoDB, PostgreSQL, SQL Server, DB2, etc.
Simple Example of SQL statements:
• SELECT "column_name" FROM "table_name";
Example of SELECT Statement:
SELECT Emp_ID, First_Name, Last_Name, Salary, City
FROM Employee_details
WHERE Salary = 100000 ;

Example of UPDATE Statement:


UPDATE Employee_details
SET Salary = 100000
WHERE Emp_ID = 10;
SQL statements:
Example of DELETE Statement:
DELETE FROM Employee_details
WHERE First_Name = ‘Umair';

Example of CREATE TABLE Statement:


CREATE TABLE Employee_details(
Emp_Id NUMBER(4) NOT NULL,
First_name VARCHAR(30),
Last_name VARCHAR(30),
Salary Money,
City VARCHAR(30),
PRIMARY KEY (Emp_Id)
);
SQL statements:
• Example of CREATE DATABASE Statement:
CREATE DATABASE Company;
• Example of insert a single record:
INSERT INTO Employee_details ( Emp_ID, First_name,Last_name, Salary,
City ) VALUES (101, Ali, Sharma, 50000,Karachi);
Example of inserting multiple records in a single query:
INSERT INTO Employee_details ( Emp_ID, First_name,Last_name, Salary,
City ) VALUES (101, Ali, Sharma, 50000,Karachi),(107, Zeeshan, Ahmed,
40000,Islamabad);
Structured Query Language (SQL)
Operations to manipulate tuples Operations to manipulate tuples
• Insert(add new record) • delete(delete exiting record or table)
• update(edit exiting record) • Select( searching for required information

26
Maintaining Database
• Transaction: A sequence of operations that must all happen together
• Example: transferring money between bank accounts
• Simultaneous access problems
• Incorrect summary problem
• Lost update problem
• Locking = preventing others from accessing data being used by a
transaction
• Shared lock: used when reading data
• Exclusive lock: used when altering data.(Read and Write both)
Maintaining Database
• Commit :Commit in SQL is a transaction control language that is used
to permanently save the changes done in the transaction in
tables/databases. The database cannot regain its previous state after its
execution of commit.
• ROLLBACK in SQL is a transactional control language that is used to
undo the transactions that have not been saved in the database.
• The process of undoing a transaction (when it is not save in database).
What is ER Model?

• ER Model stands for Entity Relationship Model is a high-level


conceptual data model diagram.
• Creating an ER Model in DBMS is considered as a best practice before
implementing your database.
• ER diagrams are visual tools that are helpful to represent the ER
model.
• ER diagrams are created based on three basic concepts: entities,
attributes and relationships.
• ER Diagrams contain different symbols that use rectangles to
represent entities, ovals to define attributes and diamond shapes to
represent relationships.
Relationship

A relationship is represented by diamond shape in ER diagram, it shows


the relationship among entities. There are four types of relationships:
1. One to One
2. One to Many
3. Many to One
4. Many to Many
Relationship

One to One Relationship:


For example, a person has only one passport and a passport is given to
one person.

One to Many Relationship:


a customer can place many orders but a order cannot be placed by
many customers.
Relationship
Relationship
Relationship
Relationship

The relationship between Student and College is many to one as a college can have many
students however a student cannot study in multiple colleges at the same time.

You might also like