Professional Documents
Culture Documents
Databases-Part I PDF
Databases-Part I PDF
• Credit Units: 20
2
Assessment Pattern
Assessment Type Weighting (%)
In-course Group Assignment 10%
Assessment (written assignments
and projects)
Individual 20%
Assignment (Online
Quizzes, written
assignments)
CAT 20%
Summative Final Exam 50%
Assessment
3
Content Outline
2. Database models
3. RDBMS
5. Normalization
6. Relational Algebra
4
Content Outline
7. Overview of PHP
5
Content Outline
12. Development of a software project using Database and PHP by
including HTML tags and CSS codes to decorate pages (setting
foreground and background colors, size, margins, applying
borders, etc.).
6
Table
• Table: It is a collection of related data held in a structured format
within a database.
7
Columns
9
Table…
Student_id name Regno Branch Address
1 Zawadi CSE-18 CSE Kicukiro
2 Yvonne IT-18 IT Nyarugenge
3 Dan CSE-18 CSE Kayonza
4 Ange CSE-18 CSE Nyagatare
10 Claire IT-18 IT Kicukiro
10
Table…
• As the student_id in students table will be unique, it can be used
easily to fetch any data.
• A primary key can be used to fetch data from any column in the
table.
• For example:
• All what I need is the student_id and other columns depend on it.
11
Exercises related to Table 1
12
Table…..
The relation schema for
Empnum name Age Deptnum
employee relation is:
3 Jones 27 1
7 Smith 34 2
11 Bob 18 1 employee(Empnum,
15 Jane 23 3 name, Age, Deptnum)
18 Mary 31 1
employees relation
13
Table…
• employee relation consists of four attributes: Empnum, name,
Age, and Deptnum. And the relation has five tuples;
14
Table…
• The relation schema is employee(Empnum, name, Age,
Deptnum)
• The set of possible values for a given attribute is called its domain.
• Thus for instance, Empnum takes its values from the domain of
employee numbers, constituted by the positive integers,
• And Age takes its values from the domain of ages, constituted by
integers between 0 and 100.
15
Table…
• Though these two domains have some values in common,
they are considered/regarded as different domains; since
the meaning given to common values is different in the
two contexts.
16
Table…
17
Table…
• In relational databases, data are stored in tables, called
relations.
18
Defining some terms
1. Tuple: A single row of a table, which contains a single record
for that relation.
19
Defining some terms…
20
5. Constraints
1. Key constraints
2. Domain constraints
21
5.1. Key Constraints
• If there are more than one such minimal subsets, these are
called candidate keys.
22
5.1. Key Constraints
23
5.2. Domain Constraints
• Attributes have specific values in real-world scenario.
• For example age can only be a positive integer.
• The same constraints have been tried to employ on the
attributes of a relation.
• Every attributes is bound to have a specific range of values.
• For example, age cannot be less than zero and telephone
numbers cannot contain a digit outside 0-9.
24
5.3. Referential integrity Constraints
• They work on the Companies Table
concept of foreign keys. Company_id Company_name Company_address
1 CIMERWA Bugarama
• A foreign key is a column 2 URWIBUTSO Nyirangarama
25
5.3. Referential integrity Constraints
Contact_id Company_id Contact_name Contact_title Phone Email
1 1 Jeff Spireman Vice President 2505130 jspi@yahoo.com
2 1 Bradley Cocc President 2505112 Bradley@gmail.com
3 2 Rugwiro DAF 2505511 ernru@Hotmail.com
Contacts table
26
5.3. Referential integrity Constraints
27
Database
28
Database models
29
What is a model?
31
Database models
1. Hierarchical database model
32
Database models
1. Hierarchical database model Regedit.exe (Registry Editor)
33
Database models
34
Database models
• The network model's original
inventor was Charles
Bachman, and it was
developed into a standard
specification published in 1969.
35
Database models
3. Relational database model
36
Database models
37
Database models
3. Relational database Relationships in a RDBMS
model
38
Database Types
1. Text database
39
Database Types
1. Text database
40
Database Types
2. Desktop database programs
• They allow users to enter data, store it, protect it, and
retrieve it when needed.
41
Database Types
2. Desktop database programs
42
Database Types
3. Relational databases
43
Database Types
3. Relational databases
44
Database Types
3. Relational databases
45
ODBC
• Open Database Connectivity (ODBC) is a common framework
for accessing and altering the contents of databases.
46
ODBC
• ODBC manages this by inserting a middle layer, called a
database driver, between an application and the DBMS.
• The purpose of this layer is to translate the application's data
queries into commands that the DBMS understands.
• For this to work, both the application and the DBMS must be
ODBC-compliant--that is, the application must be capable of
issuing ODBC commands and the DBMS must be capable of
responding to them.
47
DBMS
48
RDBMS
• RDBMS is a type of database management system (DBMS)
that stores data in the form of related tables.
49
SQL
50
SQL
51
MySQL
• MySQL is an open source relational database
management system (RDBMS).
52
MySQL
• LAMP is an acronym for "Linux, Apache, MySQL,
Perl/PHP/Python".
53
Using MySQL to create database and
tables
• C:\Users\HP>cd c:\
54
Using MySQL …
• c:\Program Files (x86)\EasyPHP\mysql\bin>mysql -u root -
p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or
\g.
• mysql> show databases;
• mysql> use test\g
• mysql> show tables;
• mysql> use mysql\g
55
Using MySQL …
56
Using MySQL …
58
Using MySQL …
60
Using MySQL …
61
SQL ALTER TABLE statement
62
SQL ALTER TABLE statement
63
SQL ALTER TABLE statement
64
SQL ALTER TABLE statement
65
SQL ALTER TABLE statement
66
SQL ALTER TABLE statement
67
SQL ALTER TABLE statement
iv. To change a column name but not its definition, use CHANGE or
RENAME COLUMN. i.e. ALTER TABLE t1 CHANGE b a INT NOT NULL;
69
SQL ALTER TABLE statement
• Renaming a column in MySQL
70
SQL ALTER TABLE statement
71
SQL ALTER TABLE statement
• FROM EMP