2. 14|edgar/data/1000045/0001037389-18-000160.txt
1000045|NICHOLAS FINANCIAL INC|SC 13G|2018-02-
09|edgar/data/1000045/0001258897-18-001316.txt
1000045|NICHOLAS FINANCIAL INC|SC 13G|2018-02-
13|edgar/data/1000045/0000315066-18-001444.txt
1000097|KINGDON CAPITAL MANAGEMENT, L.L.C.|13F-
HR|2018-02-14|edgar/data/1000097/0000919574-18-001804.txt
1000097|KINGDON CAPITAL MANAGEMENT, L.L.C.|SC
13G/A|2018-01-02|edgar/data/1000097/0000919574-18-
000008.txt
1000097|KINGDON CAPITAL MANAGEMENT, L.L.C.|SC
13G/A|2018-02-14|edgar/data/1000097/0000919574-18-
001760.txt
1000097|KINGDON CAPITAL MANAGEMENT, L.L.C.|SC
13G/A|2018-02-14|edgar/data/1000097/0000919574-18-
001765.txt
1000097|KINGDON CAPITAL MANAGEMENT, L.L.C.|SC
13G/A|2018-02-14|edgar/data/1000097/0000919574-18-
001773.txt
1000097|KINGDON CAPITAL MANAGEMENT, L.L.C.|SC
13G/A|2018-02-14|edgar/data/1000097/0000919574-18-
001777.txt
1000097|KINGDON CAPITAL MANAGEMENT, L.L.C.|SC
13G/A|2018-02-14|edgar/data/1000097/0000919574-18-
001785.txt
1000097|KINGDON CAPITAL MANAGEMENT, L.L.C.|SC
13G|2018-02-14|edgar/data/1000097/0000919574-18-001790.txt
1000177|NORDIC AMERICAN TANKERS Ltd|6-K|2018-02-
28|edgar/data/1000177/0000919574-18-002148.txt
1000177|NORDIC AMERICAN TANKERS Ltd|CORRESP|2018-
01-19|edgar/data/1000177/0000919574-18-000510.txt
1000177|NORDIC AMERICAN TANKERS Ltd|CORRESP|2018-
02-08|edgar/data/1000177/0000919574-18-000929.txt
1000177|NORDIC AMERICAN TANKERS Ltd|CORRESP|2018-
02-22|edgar/data/1000177/0000919574-18-001989.txt
1000177|NORDIC AMERICAN TANKERS Ltd|CORRESP|2018-
3. 03-02|edgar/data/1000177/0000919574-18-002224.txt
1000177|NORDIC AMERICAN TANKERS Ltd|SC 13G|2018-
01-12|edgar/data/1000177/0000895421-18-000006.txt
1000177|NORDIC AMERICAN TANKERS Ltd|UPLOAD|2018-
02-05|edgar/data/1000177/0000000000-18-004057.txt
1000177|NORDIC AMERICAN TANKERS Ltd|UPLOAD|2018-
03-19|edgar/data/1000177/0000000000-18-008366.txt
1000184|SAP SE|20-F|2018-02-
28|edgar/data/1000184/0001104659-18-013050.txt
1000184|SAP SE|6-K|2018-01-
30|edgar/data/1000184/0001104659-18-005109.txt
1000184|SAP SE|6-K|2018-01-
31|edgar/data/1000184/0001104659-18-005283.txt
1000184|SAP SE|6-K|2018-02-
22|edgar/data/1000184/0001104659-18-011197.txt
1000184|SAP SE|6-K|2018-03-
01|edgar/data/1000184/0001104659-18-013742.txt
1000184|SAP SE|6-K|2018-03-
06|edgar/data/1000184/0001104659-18-015111.txt
1000184|SAP SE|DFAN14A|2018-01-
30|edgar/data/1000184/0001104659-18-005123.txt
1000184|SAP SE|DFAN14A|2018-01-
30|edgar/data/1000184/0001104659-18-005124.txt
1000184|SAP SE|DFAN14A|2018-01-
30|edgar/data/1000184/0001104659-18-005125.txt
1000184|SAP SE|DFAN14A|2018-01-
30|edgar/data/1000184/0001104659-18-005126.txt
# Dump File
#
# Database is ported from MS Access
#--------------------------------------------------------
4. # Program Version 3.0.138
CREATE DATABASE IF NOT EXISTS `class`;
USE `class`;
#
# Table structure for table 'Department'
#
DROP TABLE IF EXISTS `Department`;
CREATE TABLE `Department` (
`Dept_Code` VARCHAR(3) NOT NULL,
`Dept_Name` VARCHAR(20),
INDEX (`Dept_Code`),
PRIMARY KEY (`Dept_Code`)
) ENGINE=myisam DEFAULT CHARSET=utf8;
5. SET autocommit=1;
#
# Dumping data for table 'Department'
#
INSERT INTO `Department` (`Dept_Code`, `Dept_Name`)
VALUES ('Act', 'Accounting');
INSERT INTO `Department` (`Dept_Code`, `Dept_Name`)
VALUES ('Exe', 'Executive');
INSERT INTO `Department` (`Dept_Code`, `Dept_Name`)
VALUES ('Fin', 'Finance');
INSERT INTO `Department` (`Dept_Code`, `Dept_Name`)
VALUES ('Mkt', 'Marketing');
INSERT INTO `Department` (`Dept_Code`, `Dept_Name`)
VALUES ('Per', 'Personnel');
INSERT INTO `Department` (`Dept_Code`, `Dept_Name`)
VALUES ('Sal', 'Sales');
INSERT INTO `Department` (`Dept_Code`, `Dept_Name`)
VALUES ('Shp', 'Shipping');
# 7 records
6. #
# Table structure for table 'Employee'
#
DROP TABLE IF EXISTS `Employee`;
CREATE TABLE `Employee` (
`Emp_ID` INTEGER NOT NULL,
`Emp_FirstName` VARCHAR(10),
`Emp_LastName` VARCHAR(10),
`Dept_Code` VARCHAR(3),
`Emp_HireDate` DATETIME,
`Emp_CreditLimit` DECIMAL(19,4),
`Emp_Phone` VARCHAR(4),
`Emp_MgrID` INTEGER,
INDEX (`Dept_Code`),
INDEX (`Emp_ID`),
INDEX (`Emp_MgrID`),
25. 1000097|KINGDON CAPITAL MANAGEMENT, L.L.C.|SC
13G|2018-02-14|edgar/data/1000097/0000919574-18-001790.txt
1000177|NORDIC AMERICAN TANKERS Ltd|6-K|2018-02-
28|edgar/data/1000177/0000919574-18-002148.txt
1000177|NORDIC AMERICAN TANKERS Ltd|CORRESP|2018-
01-19|edgar/data/1000177/0000919574-18-000510.txt
1000177|NORDIC AMERICAN TANKERS Ltd|CORRESP|2018-
02-08|edgar/data/1000177/0000919574-18-000929.txt
1000177|NORDIC AMERICAN TANKERS Ltd|CORRESP|2018-
02-22|edgar/data/1000177/0000919574-18-001989.txt
1000177|NORDIC AMERICAN TANKERS Ltd|CORRESP|2018-
03-02|edgar/data/1000177/0000919574-18-002224.txt
1000177|NORDIC AMERICAN TANKERS Ltd|SC 13G|2018-
01-12|edgar/data/1000177/0000895421-18-000006.txt
1000177|NORDIC AMERICAN TANKERS Ltd|UPLOAD|2018-
02-05|edgar/data/1000177/0000000000-18-004057.txt
1000177|NORDIC AMERICAN TANKERS Ltd|UPLOAD|2018-
03-19|edgar/data/1000177/0000000000-18-008366.txt
1000184|SAP SE|20-F|2018-02-
28|edgar/data/1000184/0001104659-18-013050.txt
1000184|SAP SE|6-K|2018-01-
30|edgar/data/1000184/0001104659-18-005109.txt
1000184|SAP SE|6-K|2018-01-
31|edgar/data/1000184/0001104659-18-005283.txt
1000184|SAP SE|6-K|2018-02-
22|edgar/data/1000184/0001104659-18-011197.txt
1000184|SAP SE|6-K|2018-03-
01|edgar/data/1000184/0001104659-18-013742.txt
1000184|SAP SE|6-K|2018-03-
06|edgar/data/1000184/0001104659-18-015111.txt
1000184|SAP SE|DFAN14A|2018-01-
30|edgar/data/1000184/0001104659-18-005123.txt
1000184|SAP SE|DFAN14A|2018-01-
30|edgar/data/1000184/0001104659-18-005124.txt
1000184|SAP SE|DFAN14A|2018-01-
30|edgar/data/1000184/0001104659-18-005125.txt
26. 1000184|SAP SE|DFAN14A|2018-01-
30|edgar/data/1000184/0001104659-18-005126.txt
Module 5: Using Databases with Python
• File-based systems
• Database systems
• Relational databases
• Structured Query Language
ISM 6405- Dr. Milad Baghersad 1
Reference: Database Systems: Design, Implementation and
Management, 12th edition by Carlos
Coronel and Steven Morris (Cengage Learning, ISBN: 978-1-
305-62748-2)
History: traditional file-based systems
ISM 6405- Dr. Milad Baghersad 2
• Computerized manual filing systems
• Individual files for each purpose
• Each business unit had its own file system
• Organized to facilitate the expected use of the data
27. • Data processing specialist required to retrieve data and run
reports
Example: file-based systems
ISM 6405- Dr. Milad Baghersad 3
• Suppose, as a FAU student, that you need to do the following
things:
1. Register for courses
2. Pay tuition
3. Work part-time on campus
File Based Systems Illustration
ISM 6405- Dr. Milad Baghersad 4
TuitionRec (ID, name,
address, amtPaid,
balance, …)
RegRec (ID, name,
address, courses, …)
EmpRec (ID, name,
30. • Data redundancy
• Different files contain same information (ID, name, address,
etc…)
• Isolation of data in separate systems
• Data inconsistency (e.g., different ID values for the same
person)
• Lack of data integrity
• Data anomalies
• All changes may not be made successfully
• Update / Insertion / Deletion anomalies
Better approach: database systems
• Database: a collection of interrelated data
organized in such a way that it corresponds to the
needs and structure of an organization and can be
used by more than one person for more than one
application.
ISM 6405- Dr. Milad Baghersad 6
Example: database system
31. ISM 6405- Dr. Milad Baghersad 7
Tuition
payment
entry and
reports
Course
registration
entry and
reports
Work-study
data entry
and reports
Tuition payment application programs
Course registration application programs
Work-study application programs
DBMS
Database
32. Advantages of database systems
ISM 6405- Dr. Milad Baghersad 8
• Minimal data redundancy
• Data consistency
• Integration of data
• Improved data sharing
• Enforcement of standards
• Ease of application development
• Uniform security, privacy, and integrity
• Data independence from applications
• "self-describing" data stored in a data dictionary (metadata)
File-based systems often imply "flat" data files:
ISM 6405- Dr. Milad Baghersad 9
RecNo Name Address City State Zip Product Units Amount
1 John Smith 221 Main St. New York NY 08842
Television 1 $500
2 William Chin 43 1st Ave. Redmond WA 98332
Refrigerator 1 $800
33. 3 William Chin 43 1st Ave. Redmond WA 98332 Toaster
1 $80
4 Marta Dieci 2 West Ave. Reno NV 92342 Television 1
$500
5 Marta Dieci 2 West Ave. Reno NV 92342 Radio 1 $40
6 Marta Dieci 2 West Ave. Reno NV 92342 Stereo 1 $200
7 Peter Melinkoff 53 NE Rodeo Miami FL 18332
Computer 1 $1500
8 Martin Sengali 1234 5th St. Boston FL 03423
Television 1 $500
9 Martin Sengali 1234 5th St. Boston FL 03423 Stereo 1
$200
10 Martin Sengali 1234 5th St. Boston FL 03423 Radio 1
$40
11 Martin Sengali 1234 5th St. Boston FL 03423
Refrigerator 1 $80
Subset of the problems with a file-based
system:
ISM 6405- Dr. Milad Baghersad 10
• Redundancy (i.e. data duplication)
• Update anomalies
34. • Update a single address requires you to update multiple entries
• Insertion anomalies
• You cannot insert information about customer until they have
actually
purchased something
• Deletion anomalies
• If there is a single instance of a given product being sold,
and for some
reason we decide to remove the customer who purchased it, we
will lose
information about the product also
Improving data management: Types of database
models
ISM 6405- Dr. Milad Baghersad 11
• Hierarchical database model
• Tree-based approach developed in 1960's
• Based on parent-child relationships (1:M)
• Network database model
• Created to improve on hierarchical model
• Allows records to have more than one parent
35. • Can access data from multiple points
• Relational database model
Relational database model
Turing Award Winner, Edgar F. Codd’s landmark paper, “A
Relational Model of
Data for Large Shared Data Banks" (1970) laid out a new way
to organize and
access data: the Relational Model.
12
Customer(CustomerID, Name, …
Order(OrderID, CustomerID, OrderDate, …
ItemsOrdered(OrderID, ItemID, Quantity, …
Items(ItemID, Description, Price, …
This Photo by Unknown
Author is licensed under
CC BY-SA
https://en.wikipedia.org/wiki/Edgar_F._Codd
https://creativecommons.org/licenses/by-sa/3.0/
36. Flat-file database
RecNo Name Address City State Zip Product Units Amount
1 John Smith 221 Main St. New York NY 08842
Television 1 $500
2 William Chin 43 1st Ave. Redmond WA 98332
Refrigerator 1 $800
3 William Chin 43 1st Ave. Redmond WA 98332 Toaster
1 $80
4 Marta Dieci 2 West Ave. Reno NV 92342 Television 1
$500
5 Marta Dieci 2 West Ave. Reno NV 92342 Radio 1 $40
6 Marta Dieci 2 West Ave. Reno NV 92342 Stereo 1 $200
7 Peter Melinkoff 53 NE Rodeo Miami FL 18332
Computer 1 $1500
8 Martin Sengali 1234 5th St. Boston FL 03423
Television 1 $500
9 Martin Sengali 1234 5th St. Boston FL 03423 Stereo 1
$200
10 Martin Sengali 1234 5th St. Boston FL 03423 Radio 1
$40
11 Martin Sengali 1234 5th St. Boston FL 03423
Refrigerator 1 $80
37. 13
Example: relational database
14
Customer table
CusNo Name Address City State Zip
1 John Smith 221 Main St. New York NY 08842
2 William Chin 43 First Ave. Redmond WA 98332
3 Marta Dieci 2 West Ave. Reno NV 92342
4 Peter Melinkoff 53 NE Rodeo Miami FL 18332
5 Martin Sengali 1234 5th St. Boston MA 03423
CusNo Product Units Amount
1 Television 1 $500
2 Refrigerator 1 $800
2 Toaster 1 $80
3 Television 1 $500
3 Radio 1 $40
3 Stereo 1 $200
38. 4 Computer 1 $1500
5 Television 1 $500
5 Stereo 1 $200
5 Radio 1 $40
5 Refrigerator 1 $800
OrderItem table
Another database in relational form
ISBN Title PubID Price
0-103-45678-9 Iliad 1 $25.00
0-11-345678-9 Moby Dick 3 $49.00
0-12-333433-3 On Liberty 1 $25.00
0-12-345678-9 Jane Eyre 3 $49.00
0-123-45678-0 Ulysses 2 $34.00
0-321-32132-1 Balloon 3 $34.00
0-55-123456-9 Main Street 3 $22.95
0-555-55555-9 MacBeth 2 $12.00
0-91-045678-5 Hamlet 2 $20.00
41. 1-22-233700-0 4
PubID PubName PubPhone
1 Big House 123-456-7890
2 Alpha Press 999-999-9999
3 Small House 714-000-0000
BOOK
AUTHOR
PUBLISHER
BOOK/AUTHOR
15
Install MySQL Server and Workbench
Use the video: How To Install MySQL (Server and
Workbench) [05:57]
Please note as you are installing MySql, when you are
selecting Products and Features (see [02:30] in the video),
click on MySQL Connectors and add Python connector also.
If you can not add Python connector, later I will teach you
another method to connect Python and MySQL.
42. 16
https://www.youtube.com/watch?v=u96rVINbAUI
Manipulating data in databases
Structured Query Language (SQL)
• creating database and table structures
• performing data manipulation and administration
• querying the database to extract useful information
17
Categories of SQL commands
• Data Definition Language (DDL)
– Commands that define a database, including creating, altering,
and
dropping tables and stored procedures, and establishing
constraints
• CREATE TABLE, set PRIMARY KEY
• Data Manipulation Language (DML)
– Commands that are used to manipulate data and extract
information
• SELECT, UPDATE, INSERT, DELETE
43. 18
Data types
• ANSI/ISO SQL data types:
– INTEGER / SMALLINT
– DECIMAL(precision, scale)
– CHAR(n) - fixed length character data
– VARCHAR(n) - variable length character data
– DATE - Julian date format
– plus several more…
• Other DBMS add additional data types.
19
MySQL data types (cont.)
Primary date and time types:
• DATE 'YYYY-MM-DD' format
range: '1000-01-01' to '9999-12-31'
• DATETIME 'YYYY-MM-DD HH:MM:SS' format
44. range: '… 00:00:00' to '… 23:59:59'
Invalid dates and times are converted to zero values: '0000-00-
00'
Some built-in functions:
NOW( ), CURDATE( ), DATEDIFF( ), INTERVAL
DATE( ), TIME( ), DAY( ), YEAR( ), MONTH( ), etc.
20
Sample Database
Posted on course site:
• class.sql (MySQL 5.0)
• We will be running examples of queries on this database as
we cover the material, to help illustrate how the different
SQL statements work.
• I strongly recommend working through the examples on your
own as we go, in order to better understand them.
21
Sample Database (continued)
45. 6 Tables:
22
StackOverflow- Mocking data for Angular2/typescript with my
own
model type properties Licensed by Stack Exchange Network
https://stackoverflow.com/questions/41765329/mocking-data-
for-angular2-typescript-with-my-own-model-type-properties
https://stackoverflow.com/legal/acceptable-use-policy
GROUP BY
Ex: For each Dept_Code, list:
The number of employees (as count) and the total credit limit
(as
total)
23