INTRODUCTION TO
COMPUTER ENGINEERING
WEEK-10
DATABASE MANAGEMENT SYSTEMS
Dr. İdris KAHRAMAN
DATABASE
▪ Database (first in the 1980s),
▪ Where data that are related to each other are kept,
▪ A collection of data organized according to its intended use,
▪ Logically and physically defined
▪ They are repositories of knowledge.
WHY DATABASE?
WHY DATABASE?
ADVANTAGES
▪ Ensuring centralized control and consistency of data
▪ Preventing duplication of common data
▪ Ensuring that data is consistent
▪ Ensuring data integrity
▪ Ensuring data sharing
▪ Presenting to each user only the data they are interested in, in easy,
understandable structures that they are familiar with
DATABASE EXAMPLES
▪ From a simple web application to large and complex data of
international organizations, there is a need for database
applications in many areas.
✓University - Student affairs information system
✓Hospital - Patient, doctor, treatment, equipment, financial
information
✓Commercial Company - Customer, product, sales,
payment, delivery information
✓Bank - Customer, deposit, credit card, loan information
DATABASE STRUCTURE
▪ Table
▪ Record
▪ Attribute /Field
▪ Key Attribute
Field 1 Field 2 Field 3 Field 4
1
2
3
TABLE Field Value
Field / Attribute
Student_id Name_surname B_date B_place E_mail
1 Ayşe Demir 01.11.1999 Konya ayse@[Link]
2 Mehmet Yılmaz 05.12.1999 Giresun mehmet@[Link]
3 Elif Kaya 16.02.2000 Ardahan elif@[Link]
4 Ahmet Çelik 11.04.1998 Ankara ahmet@[Link]
5 Zeynep Arslan 02.01.2000 Malatya zeynep@[Link]
6 Emre Şahin 22.02.2001 Yozgat emre@[Link]
Record
-Data is stored in tables.
-Tables are groups of data organized in rows and columns.
KEY
▪ Key is the defined field(s) that is forced to be entered as a qualifier for a row.
▪ There are -2 types of keys:
▪ Primary Key
▪ Foreign Key
PRIMARY AND FOREIGN KEYS
▪ Primary key is the key data to access a record.
▪ For example, there are two Ahmet's among the students. To find the Ahmet
we want when searching, each student must have a unique number:
"student number"
▪ Foreign key is used to limit and associate the records that can be
entered in a table with the data in a certain field of another table.
▪ For example, a value that does not match the student no in the student
information table cannot be entered in the table where students' grade data
is entered.
PRIMARY AND FOREIGN KEYS
DATABASE MANAGEMENT SYSTEMS (DBMS)
▪ Create a new database,
▪ Organizing the database,
▪ Use,
▪ Develop,
▪ To maintain it
▪ A software package or system that performs a variety of complex operations.
DATABASE MANAGEMENT SYSTEMS (DBMS)
DBMS ACTORS
▪ VTYS Administrator (Admin)
▪ System engineers
▪ Designer
▪ Application developer
▪ End users
DATA TYPES
▪ In order to have information about the structure of the records
kept in the database, some properties of the fields need to be
predefined.
▪ For example;
▪ personnel registration number must be a whole number,
▪ Like the letters in the name and surname
•char, varchar, nchar, nvarchar: character data
•int, tinyint, smallint, bigint, float: integer data
•smallmoney, money: monetary values
•date, smalldatetime, datetime: date and time data
•binary, varbinary: binary data
•image, xml, time,decimal, numeric, bit, ..
CLASSIFICATION OF DBMS
➢ According to the number of users ➢ By physical location
✓ Single usage ✓ Central
✓ Multi-user ✓ Distributed
➢ By data model
✓ Flat-file
✓ Hierarchical
✓ Network
✓ Relational
✓ Object Oriented
RELATIONAL DATABASES
▪ Started to be developed by IBM in the 1970s. It was proposed by Edgar Frank Codd.
▪ Data is stored in tabular form, many tables are used and relationships are created between
tables.
▪ A relationship allows us to link a record in one table to a record in another table. This way the
data takes up less space and makes our operations easier.
▪ Almost all database programs today have this structure.
RELATIONAL DATABASES
E-R (ENTITY-RELATIONSHIP) RELATIONAL DATA MODEL
▪ ER Model
▪ Assets and Qualities
▪ Asset Cluster
▪ Key Attribute
▪ Relationships (Relation)
▪ One-on-One (1-1) relationship
▪ One-to-many (1-n,n-1) relationship
▪ Many-Many (n-m) relationship
E-R (ENTITY-RELATIONSHIP) RELATIONAL DATA MODEL
DATABASE DESIGN
[Link]/Categories are defined:
Library system: books, members, genres, borrowing operations
[Link] a table for each category:
book
members
type
borrowing operations
DATABASE DESIGN
3. Select a key field for each table:
Book table: bookid
Table of members: memberid
Table of types: typeid
Borrowing Operations table: borrowid
DATABASE DESIGN
4. Add columns to the table for each property of the objects:
Book table: bookid, name, year, author, type
Members table: memberid, namesurname, birthdate, email, phonenumber
Table of types: typeid, typename
Borrowing Transactions table: borrowid, memberid, bookid, borrowdate, delivery
date
bookid name year author type
DATABASE DESIGN
5. Relationships between tables should be defined.
For example;
memberid in the Members table - memberid in the Borrowing Transactions table
book table: bookid – bookid in the Borrowing Transactions table
Types table type and book table typeid
STRUCTURED QUERY LANGUAGE - SQL
▪ IBM starts a project called System/R to develop a relational database management system.
▪ A query language called SEQUEL (Structured English Query Language) is developed for this
system.
▪ The name of the language developed during this project, which was completed in 1979, was
changed to SQL (Structured Query Language).
SQL EXAMPLE
Example of a query built in SQL for extracting data;
SELECT FIRST NAME, LAST NAME, ADDRESS Attributes
FROM PERSONNEL Table name
WHERE BOLUMNO = 17 AND GOREV = 'Secretary’
*** Query requesting information on "name, surname and address of secretaries working in
section 17"
SQL EXAMPLE
▪ Examples of queries in -SQL language for inserting and deleting records in a table in a
database;
Table name
▪ INSERT INTO STAFF (FIRST NAME, LAST NAME, ADDRESS, POSITION, BOLUMNO) VALUES
('Mustafa', 'KARA', 'Manisa', 'Manager',18)
▪ DELETE PERSONNEL WHERE PERSONELID=‘1092'
SQL INJECTION
▪ SELECT * FROM users WHERE username = 'kullanici' AND password = 'sifre';
▪ ' OR '1'='1'; --
SELECT * FROM users WHERE username = '' OR '1'='1'; -- ' AND password = '';
BENEFITS PROVIDED BY DBMS
▪ Data duplication: The same data is not kept repeatedly on different people's
computers.
▪ Data consistency: Having several copies of the same data in different places
creates "maintenance" difficulties. Address information updated in one place
may remain un-updated in another place, leading to data inconsistency. Since
the data is kept in a table in the DBMS, data consistency is ensured.
▪ Data sharing: When a database management system is not used, data is
accessed sequentially. In other words, multiple users cannot access the same
data at the same time. In an DBMS, hundreds or thousands of accesses can be
made to the same database per second without disturbing the consistency
and integrity of the data.
BENEFITS PROVIDED BY DBMS
▪ Data integrity: If a patient record is deleted from the patient information
table, that patient's information must be deleted from all other associated
tables.
▪ Data security: Very strict restrictions are in place to prevent data from being
corrupted, either intentionally or through misuse. In addition to being
protected by a username and password to enter the database, individuals
can only see tables or specific columns within a table that they are authorized
to see.
▪ Data Independence: The programmer does not have to concern himself with
the structure and organization of the data he uses. Data independence is one
of the main objectives of DBMSs.
THANK YOU…