unit 3 database management system
unit 3 database management system
unit 3 database management system
• RDBMSs organize data into tables with logical connections, called relationships,
between them. This allows for flexible access and reassembly of data.
• E.g. the popular RDBMs include Microsoft Access, Oracle, Microsoft SQL Server,
MySQL, SQLite, IBM DB2, and PostgreSQL, MySql, MongoDB, and Maria DB.
• A relational database is based on a relational data model.
• The relational data model is a way to store and manage data in tables, which are related to
each other using common attributes.
2. Given a patient table, write five fields and their data types to
describe a patient with a data values.
Data Type Use For Size
Up to 255 characters. To control the
Text or combinations of text and numbers, such as addresses. Also numbers
Text maximum number of characters that
that do not require calculations
can be entered,
Memo Lengthy text and numbers, such as notes or descriptions. Up to 64,000 characters.
Numeric data to be used for mathematical calculations. Set the FieldSize 1, 2, 4, or 8 bytes. 16 bytes for
Number
property to define the specific Number type. Replication ID (GUID) only.
Date/Time Dates and times. 8 bytes.
Use the Currency data type to prevent rounding off during calculations.
Currency 8 bytes.
Accurate to 15 digits to the left of the decimal point and 4 digits to the right.
AutoNumb Unique sequential (incrementing by 1) or random numbers automatically 4 bytes. 16 bytes for Replication ID
er inserted when a record is added. (GUID) only.
Fields that will contain only one of two values, such as Yes/No, True/False,
Yes/No 1 bit.
On/Off.
Objects (such as Microsoft Word documents, Microsoft Excel spreadsheets,
Up to 1 gigabyte (limited by disk
OLE Object pictures, sounds, or other binary data), created in other programs using the
space).
OLE protocol,
Hyperlink Field that will store hyperlinks. A hyperlink can be a UNC path or a URL. Up to 64,000 characters.
Lookup Creates a field that allows you to choose a value from another table or from a
typically 4 bytes.
Wizard list of values using a combo box.
Cont’d
• In relational database, each table that has a key field (primary key) uniquely
identifies each record.
• This key field can be used to create relationship and link one table of data to another.
• A foreign key column in a table points to a column with unique values in another table
Classwork
• Identify entity, attributes, data types, primary/foreign, record, and type of r/ship
Group Discussion
Answer
#1
Relational database management system
• The relationship is based on relational data model
• The basic structure of a relational database is table that comprises rows that are
made up of one or more columns.
• Table represents entities or event, column represent attributes, and each row rep-resents records.
• SQL is a language for relational database.
• Primary key is a field uniquely identifies each row.
• Foreign key is a field which is a primary key in another table and used to create link
or relationship between tables.
•The most common DBMS for the last 40 years.
• Limitation - now challenged with big data – which require highly flexible and adapt-able schema.
• Examples of RDBMS include MS Access, Oracle, MongoDb, etc.
Answer
#2
Field also referred to as column is an attribute that describe the entity or the
event in a table. E.g. fields for Personincludes Name, age, address; fields
#3
A record also called a tuple, is a row in a table. E.g. a record from ‘Student’
table could be: id: ‘S1001’, name: ‘Maru’, age: 20.
At the end of this section, students will be able to:
Describe SQL
Explain the purpose of DDL, DML and DQL commands
Open SQL in MS Access.
1) DDL contains commands that allow you to create or modify tables and establish
2) DML contains commands that are used to manage the database by performing
3) DQL is used for querying or selecting all or subsets of data from a database.
Hint: the DBMS may give you other sets of commands to provide extra features.
However, the three categories of commands are common and applicable in all DBMSs.
Classwork
Activity 3.3
1. What SQL command can be used to:
create a table?
modify a table?
delete a table?
add a record to a table?
modify a record in a table?
remove a record in a table?
2. Categorize commands in question 1
under DDL, DML and DQL.
Using SQL in Microsoft Access
Microsoft Access is the default relational database program installed with the
Microsoft Office package.
It offers the functionality of a database, and the programming capabilities to
create databases easily and navigate records.
SQL command in Microsoft Access can be used to implement and manipulate.
two ways of creating a database in Microsoft Access:
https://www.youtube.com/watch?v=6XHUI9YsJlQ&list=PLzr5fRV1AGV8dEGsRkghCpXNGEFI1PFaA&index=4
ALTER TABLE command
Remove.
Add.
Primary key.
Create r/ship.
If you delete a table with record, you cannot get it back.
Class work
Create r/ship visually using ‘database tool’
A relationship helps you combine data from two or more different tables.
1) One-to-one
2) One-to- many
3) Many-to-many
Option1:
INSERT INTO table_name VALUES(value1, value2, value3…..)
OPTION2:
INSERT INTO table_name(column1, column2…..) VALUES(value1,
valu2…)
Lab work
• Activity 3.9
Update command
• Not add new record to table nor does it removes record from table
• Simply update existing records.
Syntax
UPDATE table_name SET column1= value1,column2=value2… WHERE
condition;
e.g.UPDATE teacher set T_salary=15000 WHERE T_Salary<10000;
Lab work
• Activity 3.10
Delete command
• Used to delete a record or multiple e.g.
condition; Or
Incorrectly spelled field name does not provide the expected output.
Lab work
Activity 3.13
Selecting a Limited Number of Columns
SELECT field1, [field2] FROM table [WHERE criterion];
Examples1
SELECT S_Fname, S_MName, S_LName, S_sex
FROMSTUDENT
WHERE s_sex = ‘male’;
Examples2
SELECT CustomerId, SalesDate, Amount
FROM SALES
WHERE SalesDate >= ‘15-03-2020’
Filter records on multiple criteria
Select records of a table with multiple criteria using AND and OR
Example 1
SELECT CustomerId, Sales-Date, Amount
FROM SALES
WHERE SalesDate >=’01-05-2020’ AND Amount > 12000;
Example 1
SELECT CustomerId, Sales-Date, Amount
FROM SALES
WHERE Amount <1000 OR
Amount > 15000;
SELECT Command ORDER BY Clause
Syntax
SELECT table1.column1, [table1.column2], table2.column1,
[table2.column2]
FROM table1, table2
WHERE table1.column1 = table2.column2
Example
SELECT COURSE.Course_id, COURSE.Course_name, COURSE.Grade,
CourseOffering.Semester
FROM COURSE, CourseOffering
WHERE COURSE.Course_id = CourseOffering.Course_code;
Example2
SELECT COURSE.Course_id, COURSE.Course_name, COURSE.Grade,
CourseOffering.Semester
FROM COURSE, CourseOffering
WHERE COURSE.Course_id = CourseOffering.Course_code AND Semester=’I’;
Homework
Unit3:
After you take your own short note from the pdf provided,
write the answer to the review question on your exercise
book.
Review question
(P.96-99)