Relational databases store data in tables with rows and columns to model relationships. SQLite is an embedded SQL database commonly used in applications. SQL commands like SELECT, INSERT, UPDATE, and DELETE are used to query and modify data across related tables using integer primary keys and foreign keys. Complex data relationships can be modeled through one-to-many, many-to-one, and many-to-many connections between tables joined by common attributes.
This document discusses key concepts in relational database design and management. It defines relational databases as storing data in tables that are associated through shared attributes. It also describes entities, attributes, primary keys, foreign keys, and relationships. Database normalization is introduced as a process to minimize duplication and inconsistencies by breaking tables into multiple tables and defining relationships between them. Common database operations like create, read, update, and delete are also summarized.
The document discusses various database models including flat file, hierarchical, network, relational, object-relational, and object-based models. It provides a brief history of database development, from manual files to relational databases. It describes key aspects of relational databases including how data is organized into logical tables with rows and columns.
The document discusses key concepts related to databases and SQL. It defines data and databases, and describes the main types of database management systems including hierarchical, network, and relational DBMS. It explains some key aspects of relational databases including tables, constraints like primary keys and foreign keys. The document also provides examples of common SQL statements like SELECT, WHERE, ORDER BY, GROUP BY, CREATE TABLE, DROP TABLE, INSERT, UPDATE, DELETE and JOINs.
Good database design involves structuring data to minimize duplication and inconsistencies through a process called normalization. In normalization, data is broken into multiple tables that are linked through relationships. The three main types of database relationships are one-to-one, one-to-many, and many-to-many. Primary and foreign keys are used to define these relationships and ensure referential integrity between tables. Structured Query Language (SQL) provides commands to define, manipulate, and query data in a relational database.
Unit I Database concepts - RDBMS & ORACLEDrkhanchanaR
The document provides an overview of relational database management systems (RDBMS) and Oracle. It discusses database concepts such as the relational data model, database design including normalization, and integrity rules. It also outlines the contents of 5 units that will be covered, including Oracle, SQL, PL/SQL, and database objects like procedures and triggers. Key terms discussed include entities, attributes, relationships, and the different types of keys.
The document provides an overview of information systems and databases as covered in the HSC course. It discusses different types of information systems and focuses on organizing, storing, and retrieving data with database systems. It describes skills needed to analyze database information systems and provides examples to practice these skills. Finally, it covers topics like database design, data storage and retrieval methods, and some social and ethical issues related to information systems.
This document provides an introduction to Microsoft Access databases. It defines what a database is and describes the key components of an Access database, including tables, queries, forms and reports. It also outlines common database terminology like records, fields, primary keys and relationships. Database objects in Access are described as well as different data types. The document concludes by covering how to create a new blank Access database.
The document provides an introduction to databases, including key concepts such as the three levels of viewing a database (data storage, database management system, and database applications). It discusses database types, normalization forms, common terminology like SQL, CRUD, and ACID. Examples of typical database architectures and applications are presented. The advantages of normalization for reducing redundancy and improving integrity are covered, along with some disadvantages like increased complexity and reduced efficiency for some queries.
This document discusses key concepts in relational database design and management. It defines relational databases as storing data in tables that are associated through shared attributes. It also describes entities, attributes, primary keys, foreign keys, and relationships. Database normalization is introduced as a process to minimize duplication and inconsistencies by breaking tables into multiple tables and defining relationships between them. Common database operations like create, read, update, and delete are also summarized.
The document discusses various database models including flat file, hierarchical, network, relational, object-relational, and object-based models. It provides a brief history of database development, from manual files to relational databases. It describes key aspects of relational databases including how data is organized into logical tables with rows and columns.
The document discusses key concepts related to databases and SQL. It defines data and databases, and describes the main types of database management systems including hierarchical, network, and relational DBMS. It explains some key aspects of relational databases including tables, constraints like primary keys and foreign keys. The document also provides examples of common SQL statements like SELECT, WHERE, ORDER BY, GROUP BY, CREATE TABLE, DROP TABLE, INSERT, UPDATE, DELETE and JOINs.
Good database design involves structuring data to minimize duplication and inconsistencies through a process called normalization. In normalization, data is broken into multiple tables that are linked through relationships. The three main types of database relationships are one-to-one, one-to-many, and many-to-many. Primary and foreign keys are used to define these relationships and ensure referential integrity between tables. Structured Query Language (SQL) provides commands to define, manipulate, and query data in a relational database.
Unit I Database concepts - RDBMS & ORACLEDrkhanchanaR
The document provides an overview of relational database management systems (RDBMS) and Oracle. It discusses database concepts such as the relational data model, database design including normalization, and integrity rules. It also outlines the contents of 5 units that will be covered, including Oracle, SQL, PL/SQL, and database objects like procedures and triggers. Key terms discussed include entities, attributes, relationships, and the different types of keys.
The document provides an overview of information systems and databases as covered in the HSC course. It discusses different types of information systems and focuses on organizing, storing, and retrieving data with database systems. It describes skills needed to analyze database information systems and provides examples to practice these skills. Finally, it covers topics like database design, data storage and retrieval methods, and some social and ethical issues related to information systems.
This document provides an introduction to Microsoft Access databases. It defines what a database is and describes the key components of an Access database, including tables, queries, forms and reports. It also outlines common database terminology like records, fields, primary keys and relationships. Database objects in Access are described as well as different data types. The document concludes by covering how to create a new blank Access database.
The document provides an introduction to databases, including key concepts such as the three levels of viewing a database (data storage, database management system, and database applications). It discusses database types, normalization forms, common terminology like SQL, CRUD, and ACID. Examples of typical database architectures and applications are presented. The advantages of normalization for reducing redundancy and improving integrity are covered, along with some disadvantages like increased complexity and reduced efficiency for some queries.
A database management system (DBMS) is a collection of programs that enables users to create and maintain databases and control all access to them. The primary goal of a DBMS is to provide an environment that is both convenient and efficient for users to retrieve and store information.
This document defines basic database terminology and concepts. It describes key terms like database, tables, fields, records, cells, and objects. It also explains the differences between a database instance and schema. Additionally, it outlines the three schema architecture and how it provides data independence. Finally, it briefly discusses database system components, interfaces, utilities, and classification.
Data is a collection of distinct pieces of information that can be stored and processed digitally. A database is an organized collection of structured data stored digitally. A database management system (DBMS) is software that allows users to define, create, maintain and control access to a database. Common DBMSs include Oracle, SQL Server, and MySQL. Relational databases organize data into tables with rows and columns and allow users to define relationships between tables. Keys like primary keys and foreign keys help define these relationships and uniquely identify rows. Structured Query Language (SQL) is used to communicate with databases to perform operations like querying and updating data.
This document provides an introduction to database management systems (DBMS) and SQL Server. It discusses what a database is and where databases are used. It then describes DBMS as software that allows users to define, create, query, update and administer databases. Common DBMS examples include Oracle, MySQL, PostgreSQL and SQL Server. The document goes on to explain relational databases and the entity-relationship model. It also covers key concepts like tables, rows, columns, primary keys and foreign keys. Finally, it discusses the major SQL statements: DDL for defining database structure, DML for managing data, and DCL for controlling access privileges.
This document provides an introduction to database management systems (DBMS). It defines key terminology related to databases and discusses problems with manual databases. It describes the functions and advantages of DBMS, including data representation, transaction management, data sharing, and increased security. Examples of popular DBMS are provided, such as Oracle, Microsoft SQL Server, and MySQL. Database system architecture, data models, and the relational model are overviewed. Finally, entity relationship (ER) modeling is explained as a way to conceptualize data needs and design the database logically before implementation.
This document provides an overview of database management systems. It defines key database concepts like entities, fields, records and tables. It describes different database models like hierarchical, network, relational and object-oriented models. It also explains relational database structures, the role of a database management system, querying databases using SQL, and common database functions like creating tables, sorting records, generating reports and database normalization.
Advanced Database Systems - Presentation 1 with quiz.pptxEllenGracePorras
Here are the answers to the quiz questions:
1. A database is a structured collection of related data.
2. Data is a collection of facts made up of text, numbers and dates. Information is the meaning given to data in the way it is interpreted.
3. Examples of data: name, age, address. Examples of information: Mr. Smith is 35 years old and lives at 123 Main St.
4. SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in relational database.
5. A Primary Key is a field that that will contain no duplicates and no blank values.
6. The 3 basic database concepts are: table
The document discusses relational databases and how they organize data into tables that can be accessed and reassembled in different ways without reorganizing the tables, it also covers how PeopleSoft uses a 3-tier architecture called PeopleSoft Internet Architecture (PIA) consisting of a web browser, web server, application server and database server to deliver pure internet applications to users. PIA provides advantages over traditional client/server architectures like thin clients, improved performance, and the ability to scale more easily to meet increasing user demands.
This document provides an introduction to relational databases and SQL. It defines what a database is and explains that data is stored in tables in a relational database. It describes the components of relational tables like primary keys, fields, and records. The document outlines the terminology used in relational modeling and discusses concepts like relations, attributes, domains and more. It also covers SQL, database management systems, keys, and provides an overview of the MySQL database.
The document provides an overview of SQL Server training. It defines data and databases, explaining that a collection of data leads to a database. It also discusses database management systems (DBMS), explaining that a DBMS allows users to create, read, update and delete data in an organized way. The document also covers types of databases like hierarchical, network, relational and object-oriented databases. It focuses on relational database management systems (RDBMS) and discusses advantages like storing data uniquely and performing complex queries. Finally, it discusses Microsoft SQL Server in more detail.
The document discusses different types of databases including relational databases, analytical databases, operational databases, and object-oriented databases. It describes key characteristics of each type of database such as how they model and store data. Relational databases use tables to store data and link tables using relationships while analytical databases store archived data for analysis and operational databases manage dynamic data. Object-oriented databases integrate object-oriented programming with databases.
This document provides an introduction to database management systems (DBMS) and SQL Server. It discusses what a database is and where databases are used. It then explains what a DBMS is and some examples of DBMS software. The document goes on to describe the relational database model including entities, attributes, relationships and keys. It also discusses the entity-relationship model. Finally, it covers SQL statements including DDL, DML, and DCL and provides examples of commands for creating tables, inserting and updating data, and setting privileges.
This document provides an overview of database management systems and different types of databases. It discusses how databases store and organize data, the roles of database analysts and administrators, features of database management systems like data maintenance, security, and backups. It also introduces different data models including relational, object-oriented, and multi-dimensional databases, comparing their data storage, specialties, benefits, and sample applications.
Data Science, Statistical Analysis and R... Learn what those mean, how they can help you find answers to your questions and complement the existing toolsets and processes you are currently using to make sense of data. We will explore R and the RStudio development environment, installing and using R packages, basic and essential data structures and data types, plotting graphics, manipulating data frames and how to connect R and SQL Server.
This document provides an introduction to database management systems (DBMS) and MySQL. It defines a database as a collection of organized information that can be quickly accessed by a computer program. A DBMS helps create and manage databases, similar to how MS Word helps create documents. The document discusses the entity-relationship model and how entities are represented as tables with attributes as columns. It provides examples of creating tables, adding primary keys, and linking tables with foreign keys. It also explains the three types of SQL statements - DDL for defining the database structure, DML for managing data, and DCL for controlling access. Specific DDL, DML, and DCL commands are defined along with syntax examples.
The document provides an overview of database management systems (DBMS). It begins with introducing the presenters and objective to make the audience knowledgeable about DBMS fundamentals and improvements. The contents section outlines topics like introduction, data, information, database components, what is a DBMS, database administrator, database languages, advantages and disadvantages of DBMS, examples of DBMS like SQL Server, and applications of DBMS.
This document discusses key concepts related to databases including:
- Data hierarchy refers to the organization of data in a database with tables containing records made up of individual fields.
- A contact list on a mobile phone is an example of a simple database with tables (contacts), records (individual contacts) and fields (name, phone number, etc.).
- Primary keys uniquely identify each record in a table while foreign keys in one table match the primary key of another table to link the tables together in a relational database.
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...Marlon Dumas
This webinar discusses the limitations of traditional approaches for business process simulation based on had-crafted model with restrictive assumptions. It shows how process mining techniques can be assembled together to discover high-fidelity digital twins of end-to-end processes from event data.
A database management system (DBMS) is a collection of programs that enables users to create and maintain databases and control all access to them. The primary goal of a DBMS is to provide an environment that is both convenient and efficient for users to retrieve and store information.
This document defines basic database terminology and concepts. It describes key terms like database, tables, fields, records, cells, and objects. It also explains the differences between a database instance and schema. Additionally, it outlines the three schema architecture and how it provides data independence. Finally, it briefly discusses database system components, interfaces, utilities, and classification.
Data is a collection of distinct pieces of information that can be stored and processed digitally. A database is an organized collection of structured data stored digitally. A database management system (DBMS) is software that allows users to define, create, maintain and control access to a database. Common DBMSs include Oracle, SQL Server, and MySQL. Relational databases organize data into tables with rows and columns and allow users to define relationships between tables. Keys like primary keys and foreign keys help define these relationships and uniquely identify rows. Structured Query Language (SQL) is used to communicate with databases to perform operations like querying and updating data.
This document provides an introduction to database management systems (DBMS) and SQL Server. It discusses what a database is and where databases are used. It then describes DBMS as software that allows users to define, create, query, update and administer databases. Common DBMS examples include Oracle, MySQL, PostgreSQL and SQL Server. The document goes on to explain relational databases and the entity-relationship model. It also covers key concepts like tables, rows, columns, primary keys and foreign keys. Finally, it discusses the major SQL statements: DDL for defining database structure, DML for managing data, and DCL for controlling access privileges.
This document provides an introduction to database management systems (DBMS). It defines key terminology related to databases and discusses problems with manual databases. It describes the functions and advantages of DBMS, including data representation, transaction management, data sharing, and increased security. Examples of popular DBMS are provided, such as Oracle, Microsoft SQL Server, and MySQL. Database system architecture, data models, and the relational model are overviewed. Finally, entity relationship (ER) modeling is explained as a way to conceptualize data needs and design the database logically before implementation.
This document provides an overview of database management systems. It defines key database concepts like entities, fields, records and tables. It describes different database models like hierarchical, network, relational and object-oriented models. It also explains relational database structures, the role of a database management system, querying databases using SQL, and common database functions like creating tables, sorting records, generating reports and database normalization.
Advanced Database Systems - Presentation 1 with quiz.pptxEllenGracePorras
Here are the answers to the quiz questions:
1. A database is a structured collection of related data.
2. Data is a collection of facts made up of text, numbers and dates. Information is the meaning given to data in the way it is interpreted.
3. Examples of data: name, age, address. Examples of information: Mr. Smith is 35 years old and lives at 123 Main St.
4. SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in relational database.
5. A Primary Key is a field that that will contain no duplicates and no blank values.
6. The 3 basic database concepts are: table
The document discusses relational databases and how they organize data into tables that can be accessed and reassembled in different ways without reorganizing the tables, it also covers how PeopleSoft uses a 3-tier architecture called PeopleSoft Internet Architecture (PIA) consisting of a web browser, web server, application server and database server to deliver pure internet applications to users. PIA provides advantages over traditional client/server architectures like thin clients, improved performance, and the ability to scale more easily to meet increasing user demands.
This document provides an introduction to relational databases and SQL. It defines what a database is and explains that data is stored in tables in a relational database. It describes the components of relational tables like primary keys, fields, and records. The document outlines the terminology used in relational modeling and discusses concepts like relations, attributes, domains and more. It also covers SQL, database management systems, keys, and provides an overview of the MySQL database.
The document provides an overview of SQL Server training. It defines data and databases, explaining that a collection of data leads to a database. It also discusses database management systems (DBMS), explaining that a DBMS allows users to create, read, update and delete data in an organized way. The document also covers types of databases like hierarchical, network, relational and object-oriented databases. It focuses on relational database management systems (RDBMS) and discusses advantages like storing data uniquely and performing complex queries. Finally, it discusses Microsoft SQL Server in more detail.
The document discusses different types of databases including relational databases, analytical databases, operational databases, and object-oriented databases. It describes key characteristics of each type of database such as how they model and store data. Relational databases use tables to store data and link tables using relationships while analytical databases store archived data for analysis and operational databases manage dynamic data. Object-oriented databases integrate object-oriented programming with databases.
This document provides an introduction to database management systems (DBMS) and SQL Server. It discusses what a database is and where databases are used. It then explains what a DBMS is and some examples of DBMS software. The document goes on to describe the relational database model including entities, attributes, relationships and keys. It also discusses the entity-relationship model. Finally, it covers SQL statements including DDL, DML, and DCL and provides examples of commands for creating tables, inserting and updating data, and setting privileges.
This document provides an overview of database management systems and different types of databases. It discusses how databases store and organize data, the roles of database analysts and administrators, features of database management systems like data maintenance, security, and backups. It also introduces different data models including relational, object-oriented, and multi-dimensional databases, comparing their data storage, specialties, benefits, and sample applications.
Data Science, Statistical Analysis and R... Learn what those mean, how they can help you find answers to your questions and complement the existing toolsets and processes you are currently using to make sense of data. We will explore R and the RStudio development environment, installing and using R packages, basic and essential data structures and data types, plotting graphics, manipulating data frames and how to connect R and SQL Server.
This document provides an introduction to database management systems (DBMS) and MySQL. It defines a database as a collection of organized information that can be quickly accessed by a computer program. A DBMS helps create and manage databases, similar to how MS Word helps create documents. The document discusses the entity-relationship model and how entities are represented as tables with attributes as columns. It provides examples of creating tables, adding primary keys, and linking tables with foreign keys. It also explains the three types of SQL statements - DDL for defining the database structure, DML for managing data, and DCL for controlling access. Specific DDL, DML, and DCL commands are defined along with syntax examples.
The document provides an overview of database management systems (DBMS). It begins with introducing the presenters and objective to make the audience knowledgeable about DBMS fundamentals and improvements. The contents section outlines topics like introduction, data, information, database components, what is a DBMS, database administrator, database languages, advantages and disadvantages of DBMS, examples of DBMS like SQL Server, and applications of DBMS.
This document discusses key concepts related to databases including:
- Data hierarchy refers to the organization of data in a database with tables containing records made up of individual fields.
- A contact list on a mobile phone is an example of a simple database with tables (contacts), records (individual contacts) and fields (name, phone number, etc.).
- Primary keys uniquely identify each record in a table while foreign keys in one table match the primary key of another table to link the tables together in a relational database.
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...Marlon Dumas
This webinar discusses the limitations of traditional approaches for business process simulation based on had-crafted model with restrictive assumptions. It shows how process mining techniques can be assembled together to discover high-fidelity digital twins of end-to-end processes from event data.
Generative Classifiers: Classifying with Bayesian decision theory, Bayes’ rule, Naïve Bayes classifier.
Discriminative Classifiers: Logistic Regression, Decision Trees: Training and Visualizing a Decision Tree, Making Predictions, Estimating Class Probabilities, The CART Training Algorithm, Attribute selection measures- Gini impurity; Entropy, Regularization Hyperparameters, Regression Trees, Linear Support vector machines.
4. Random Access
• When you can randomly
access data...
• How can you layout data
to be most efficient?
• Sorting might not be the
best idea
https://en.wikipedia.org/wiki/Hard_disk_drive_platter
6. Terminology
• Database - contains many tables
• Relation (or table) - contains tuples and attributes
• Tuple (or row) - a set of fields that generally represents an “object”
like a person or a music track
• Attribute (also column or field) - one of possibly many elements of
data corresponding to the object represented by the row
7. A relation is defined as a set of tuples that have the same attributes. A tuple usually represents
an object and information about that object. Objects are typically physical objects or concepts.
A relation is usually described as a table, which is organized into rows and columns. All the
data referenced by an attribute are in the same domain and conform to the same constraints.
(Wikipedia)
9. SQL
Structured Query Language is the language we use to issue
commands to the database
- Create data (a.k.a Insert)
- Retrieve data
- Update data
- Delete data
http://en.wikipedia.org/wiki/SQL
11. Web Applications w/ Databases
• Application Developer - Builds the logic for the application, the look
and feel of the application - monitors the application for problems
• Database Administrator - Monitors and adjusts the database as the
program runs in production
• Often both people participate in the building of the “Data model”
13. Database Administrator
http://en.wikipedia.org/wiki/Database_administrator
A database administrator (DBA) is a person responsible for the
design, implementation, maintenance, and repair of an
organization’s database. The role includes the development and
design of database strategies, monitoring and improving
database performance and capacity, and planning for future
expansion requirements. They may also plan, coordinate, and
implement security measures to safeguard the database.
14. Database Model
http://en.wikipedia.org/wiki/Database_model
A database model or database schema is the structure
or format of a database, described in a formal language
supported by the database management system. In
other words, a “database model” is the application of a
data model when used in conjunction with a database
management system.
15. Common Database Systems
• Three major Database Management Systems in wide use
- Oracle - Large, commercial, enterprise-scale, very very tweakable
- MySql - Simpler but very fast and scalable - commercial open source
- SqlServer - Very nice - from Microsoft (also Access)
• Many other smaller projects, free and open source
- HSQL, SQLite, Postgres, ...
16. SQLite is in Lots of Software...
http://www.sqlite.org/famous.html
17. SQLite Browser
• SQLite is a very popular database - it is free and fast and small
• SQLite Browser allows us to directly manipulate SQLite files
• http://sqlitebrowser.org/
• SQLite is embedded in Python and a number of other languages
24. SQL: Insert
The Insert statement inserts a row into a table
INSERT INTO Users (name, email) VALUES ('Kristin', 'kf@umich.edu')
25.
26.
27. SQL: Delete
Deletes a row in a table based on selection criteria
DELETE FROM Users WHERE email='ted@umich.edu'
28.
29.
30. SQL: Update
Allows the updating of a field with a where clause
UPDATE Users SET name='Charles' WHERE
email='csev@umich.edu'
31.
32.
33. Retrieving Records: Select
The select statement retrieves a group of records - you can either
retrieve all the records or a subset of the records with a WHERE
clause
SELECT * FROM Users
SELECT * FROM Users WHERE email='csev@umich.edu'
34.
35.
36. Sorting with ORDER BY
You can add an ORDER BY clause to SELECT statements to get
the results sorted in ascending or descending order
SELECT * FROM Users ORDER BY email
SELECT * FROM Users ORDER BY name DESC
37.
38. SQL Summary
SELECT * FROM Users
SELECT * FROM Users WHERE email='csev@umich.edu'
UPDATE Users SET name="Charles" WHERE email='csev@umich.edu'
INSERT INTO Users (name, email) VALUES ('Kristin', 'kf@umich.edu')
DELETE FROM Users WHERE email='ted@umich.edu'
SELECT * FROM Users ORDER BY email
39. This is not too exciting (so far)
• Tables pretty much look like big fast programmable spreadsheets
with rows, columns, and commands
• The power comes when we have more than one table and we can
exploit the relationships between the tables
40. Complex Data Models and
Relationships
http://en.wikipedia.org/wiki/Relational_model
41. Database Design
• Database design is an art form of its own with particular skills and
experience
• Our goal is to avoid the really bad mistakes and design clean and
easily understood databases
• Others may performance tune things later
• Database design starts with a picture...
42.
43.
44. Building a Data Model
• Drawing a picture of the data objects for our application and then
figuring out how to represent the objects and their relationships
• Basic Rule: Don’t put the same string data in twice - use a
relationship instead
• When there is one thing in the “real world” there should be one
copy of that thing in the database
46. For each “piece of info”...
• Is the column an object or an attribute of
another object?
• Once we define objects, we need to define
the relationships between objects Track
Len
Artist
Album
Genre
Rating
Count
51. Database Normalization (3NF)
• There is *tons* of database theory - way too much to understand
without excessive predicate calculus
• Do not replicate data - reference data - point at data
• Use integers for keys and for references
• Add a special “key” column to each table which we will make
references to. By convention, many programmers call this
column “id”
http://en.wikipedia.org/wiki/Database_normalization
52. We want to keep track of which band is the “creator” of each music track...
What album does this song “belong to”??
Which album is this song related to?
54. Three Kinds of Keys
• Primary key - generally an integer auto-
increment field
• Logical key - What the outside world uses
for lookup
• Foreign key - generally an integer key
pointing to a row in another table
Album
id
title
artist_id
...
55. Key Rules
Best practices
• Never use your logical key as the primary
key
• Logical keys can and do change, albeit
slowly
• Relationships that are based on matching
string fields are less efficient than integers
User
id
login
password
name
email
created_at
modified_at
login_at
56. Foreign Keys
• A foreign key is when a table has a
column that contains a key which
points to the primary key of another
table.
• When all primary keys are integers,
then all foreign keys are integers - this
is good - very good
Artist
id
name
...
Album
id
title
artist_id
...
62. CREATE TABLE Genre (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name TEXT
)
63. CREATE TABLE Track (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
title TEXT,
album_id INTEGER,
genre_id INTEGER,
len INTEGER, rating INTEGER, count INTEGER
)
CREATE TABLE Album (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
artist_id INTEGER,
title TEXT
)
64.
65. insert into Artist (name) values ('Led Zepplin')
insert into Artist (name) values ('AC/DC')
66. insert into Artist (name) values ('Led Zepplin')
insert into Artist (name) values ('AC/DC')
67. insert into Genre (name) values ('Rock')
insert into Genre (name) values ('Metal')
68. insert into Album (title, artist_id) values ('Who Made Who', 2)
insert into Album (title, artist_id) values ('IV', 1)
72. Relational Power
• By removing the replicated data and replacing it with references to
a single copy of each bit of data we build a “web” of information
that the relational database can read through very quickly - even
for very large amounts of data
• Often when you want some data it comes from a number of tables
linked by these foreign keys
73. The JOIN Operation
• The JOIN operation links across several tables as part of a select
operation
• You must tell the JOIN how to use the keys that make the
connection between the tables using an ON clause
74. select Album.title, Artist.name from Album join Artist on Album.artist_id = Artist.id
What we want
to see
The tables that
hold the data
How the tables
are linked
Artist
Album
77. select Track.title, Genre.name from Track join Genre on Track.genre_id = Genre.id
What we want
to see
The tables that
hold the data
How the tables
are linked
78. select Track.title, Artist.name, Album.title,
Genre.name from Track join Genre join Album join
Artist on Track.genre_id = Genre.id and
Track.album_id = Album.id and Album.artist_id =
Artist.id
What we want to see
The tables which hold
the data
How the tables are
linked
83. Many to Many
• Sometimes we need to model a
relationship that is many-to-many
• We need to add a "connection"
table with two foreign keys
• There is usually no separate
primary key
https://en.wikipedia.org/wiki/Many-to-many_(data_model)
85. Start with a Fresh
Database
CREATE TABLE User (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name TEXT UNIQUE,
email TEXT
)
CREATE TABLE Course (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
title TEXT UNIQUE
)
CREATE TABLE Member (
user_id INTEGER,
course_id INTEGER,
role INTEGER,
PRIMARY KEY (user_id, course_id)
)
86.
87. Insert Users and Courses
INSERT INTO User (name, email) VALUES ('Jane', 'jane@tsugi.org');
INSERT INTO User (name, email) VALUES ('Ed', 'ed@tsugi.org');
INSERT INTO User (name, email) VALUES ('Sue', 'sue@tsugi.org');
INSERT INTO Course (title) VALUES ('Python');
INSERT INTO Course (title) VALUES ('SQL');
INSERT INTO Course (title) VALUES ('PHP');
88.
89. INSERT INTO Member (user_id, course_id, role) VALUES (1, 1, 1);
INSERT INTO Member (user_id, course_id, role) VALUES (2, 1, 0);
INSERT INTO Member (user_id, course_id, role) VALUES (3, 1, 0);
INSERT INTO Member (user_id, course_id, role) VALUES (1, 2, 0);
INSERT INTO Member (user_id, course_id, role) VALUES (2, 2, 1);
INSERT INTO Member (user_id, course_id, role) VALUES (2, 3, 1);
INSERT INTO Member (user_id, course_id, role) VALUES (3, 3, 0);
90.
91. SELECT User.name, Member.role, Course.title
FROM User JOIN Member JOIN Course
ON Member.user_id = User.id AND
Member.course_id = Course.id
ORDER BY Course.title, Member.role DESC, User.name
93. Complexity Enables Speed
• Complexity makes speed possible and allows you to get very fast
results as the data size grows
• By normalizing the data and linking it with integer keys, the overall
amount of data which the relational database must scan is far
lower than if the data were simply flattened out
• It might seem like a tradeoff - spend some time designing your
database so it continues to be fast when your application is a
success
94. Additional SQL Topics
• Indexes improve access performance for things like string fields
• Constraints on data - (cannot be NULL, etc..)
• Transactions - allow SQL operations to be grouped and done as a
unit
95. Summary
• Relational databases allow us to scale to very large amounts of
data
• The key is to have one copy of any data element and use relations
and joins to link the data to multiple places
• This greatly reduces the amount of data which much be scanned
when doing complex operations across large amounts of data
• Database and SQL design is a bit of an art form
96. Acknowledgements / Contributions
These slides are Copyright 2010- Charles R. Severance (www.dr-
chuck.com) of the University of Michigan School of Information
and open.umich.edu and made available under a Creative
Commons Attribution 4.0 License. Please maintain this last slide
in all copies of the document to comply with the attribution
requirements of the license. If you make a change, feel free to
add your name and organization to the list of contributors on this
page as you republish the materials.
Initial Development: Charles Severance, University of Michigan
School of Information
… Insert new Contributors here
...