
Understanding Database Terminology and Persistence in Software Engineering
Dive into the world of database terminology and software persistence, exploring concepts like fields, records, databases, and the importance of persistence in software development. Learn about the lifespan of data, variable persistence, and the key role databases play in storing and managing information effectively.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Our journey so far 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 1
And now for something completely different 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 2
Databases SWEN-250
Persistence First a detour Persistence is the key to solving most mysteries. Christopher Pike, Black Blood Persistence when you are stuck on a piece of new code is hardly ever a virtue. Try redesigning the class, try an alternative coding approach, or try coming back to it later. When one approach isn t working, that s a good time to try an alternative Robert Pirsig, Zen and the Art of Motorcycle Maintenance 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 4
Persistence Software Persistence refers to the life span of a piece of data. Variables can persist: For a particular block of code (e.g. loop or function) Until you allow them to (in java garbage collected; in C/C++ until you delete) For the life of the program (global variables or static ones) Forever (as in that which is stored in a Database) 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 5
Database terminology Field: smallest item of stored data. For example, a character string associated with a type of information: Alumni s FirstName Record: group of related fields and associated values For example, the collection of attributes associated to an Alumni: FirstName Katie LastName Linendoll Class UnivID 2005 145-254-2541 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 7
Database terminology Database file or Table: collection of related records that are frequently categorized for given purpose. FirstName LastName Class Katie Linendoll Alex Kipman Robert Duffy UnivID XXXXX4-2541 985-65-6258 XXXXX5-8574 XXXX 2001 XXXX 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 8
Database terminology Database: a collection of related tables Database Management System (DBMS): a system providing control over definition, access and manipulation of the information stored in the database Application Programs/Queries Query Processing DBMS Software Data Access Database Definition (Meta-data) Data 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 9
Database (history) Early database systems were ad hoc Hierarchical and Navigational Models Affords parent-child structure but is restrictive and it is hard to maintain links. Relational Databases Ignores how files are connected and organizes data into two-dimensional unordered-tables Data can be separated into multiple tables Leverages relational algebra & relational calculus No need for expensive rewrites of links Object-oriented Databases Seeks optimization by organizing data as objects and their attributes Often challenged by the translation to/from objects 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 10
Database (recent history) NoSQL Databases incorporate any number of approaches such as: Replication across nodes in a cluster Fast key-value stores Schema-free document storage Extensible columns XML oriented attributes 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 11
Example Baseball Database $ sqlite3 baseball.db SQLite version 3.7.9 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table Players (id integer primary key, name text, team_id integer, position text) ; create table Teams (id integer primary key, name text, city text) ; .schema Players Teams id name team_id position id name city
Example Adding Rows -- This is a comment -- Insert First team info insert into Teams (name, city) values ("Yankees", "New York"); Teams id name 1 Yankees New York city * The primary key (id) is automatically incremented on inserts
Example Adding Rows Players Teams id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals 5 Mets city New York Boston San Francisco St. Louis New York id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS -- This is a comment -- Insert Stephen Drew the primary key is auto-incremented to ensure uniqueness. insert into Players (name, team_id, position) values ("Stephen Drew", 2, "SS");
Example Retrieving Data Operator: Select -- List the Players table select * from Players ; -- List the Teams table select * from Teams ; Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York select * means ALL THE COLUMNS
Example Retrieving Data Operator: Select with additional criteria Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the Players table plus criteria select * from Players where position = "OF" ;
Operator: Select Retrieve rows based on criteria Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the Players table plus criteria select * from Players where position = "OF" ;
Operator: Select Select some rows based on criteria Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the Teams table plus criteria select * from Teams where city = "New York";
Operator: Select Select some rows based on criteria Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the Teams table select * from Teams where city = "New York";
Operator: Select Select some rows based on criteria Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the name and position of each player select name, position from Players ; -- List the name and city of each team select name, city from Teams ;
Operator: Select Choose only some of the columns Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the name and position of each player select name, position from Players ; -- List the name and city of each team select name, city from Teams ;
Operator: Select Choose only some of the columns Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the name and position of each player select name, position from Players ; -- List the name and city of each team select name, city from Teams ;
Operator: Select with LIKE Choose only some of the columns with wildcard Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the name any player team with an p in the name select name from Players WHERE name LIKE %p% ; (2 results) select name from Players WHERE name LIKE p% ; (1 result)
Warning !!! All DBMS s are not alike There are syntax differences between MS SQL MySQL Sqlite Oracle Queries are order of operation sensitive where a=1 or a=2 and b=3 When in doubt, use parentheses! 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 24
Operator: Join Match rows from one table against another Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York Foreign Key Column It will complete this process for ALL team_id s -- List all combinations of Players & Teams (not very useful) -- List all combinations of Players & Teams (not very useful) select * from Players, Teams ; select * from Players, Teams ; -- List combinations where Player's team_id = Teams' id (join & select) -- List combinations where Player's team_id = Teams' id (join & select) select * from Players, Teams where Players.team_id = Teams.id ; select * from Players, Teams where Players.team_id = Teams.id ;
Exercises Join / Select / Project Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the names of the out fielders playing in New York select Players.name from Players, Teams where Players.team_id = Teams.id and Players.position = "OF " Players.position = "OF " and Teams.city = "New York" ; -- List the names of the out fielders playing in New York select Players.name from Players, Teams where Players.team_id = Teams.id and
Exercises Join / Select / Project Players Teams id name 1 Ichiro Suzuki 2 Derek Jeter 3 Jacoby Ellsbury 4 Pablo Sandoval 5 Dustin Pedroia 6 Matt Holiday 7 Carlos Beltran 8 Ike Davis 9 Stephen Drew team_id position 1 OF 1 SS 2 OF 3 3B 2 2B 5 OF 5 OF 4 1B 2 SS id name 1 Yankees 2 Red Sox 3 Giants 4 Cardinals St. Louis 5 Mets city New York Boston San Francisco New York -- List the cities of all the short stops select Teams.city from Players, Teams where Players.team_id; -- Only shows city for each and all players -- we need to filter the SS position select Teams.city from Players, Teams where Players.team_id = Teams.id and Players.position = "SS" ;
What About Players w/ Multiple Teams? Example: See Ichiro Suzuki 2012 Season Started season with Seattle - Mariners Ended season with New York - Yankees Approach #1: Duplicate records what we have That is, two or more records for a player one per position. Issue of redundancy (DRY violation). Approach #2: Table for player Table for team Table linking players to teams
Linking Table (a way to capture Relationship) Players id name Ichiro Suzuki Derek Jeter Jacoby Ellsbury OF Pablo Sandoval 3B Dustin Pedroia 2B Matt Holiday Carlos Beltran Ike Davis Stephen Drew position OF SS PlayersTeams 1 2 3 4 5 6 7 8 9 player_id team_id 1 2 3 4 5 6 7 8 9 1 1 1 2 3 2 5 5 4 2 6 OF OF 1B SS Teams id name Yankees Red Sox Giants Cardinals St. Louis Mets Mariners Seattle city New York Boston San Francisco 1 2 3 4 5 6 Can do the same for other duplicates like players with multiple positions New York
SQLManager for Firefox Installation: From Firefox visit firefox/addon/sqlite-manager/ Select the Add to Firefox button. Follow the installation instructions [You may have to restart Firefox] Open the manager it's in the Firefox Menu Bar under Tools. You can either open an existing database or create a new one. As you manipulate the database, you'll see the SQL statements that are executed. Joins require you to type the SQL in the Execute SQL tab.
Another query example These two methods give an equivalent result explicit JOIN vs implicit sqlite> SELECT Coach.name, Coach.number FROM Coach INNER JOIN Player ON Player.team = Coach.team WHERE Player.name="Hanley Ramirez" AND Coach.title LIKE '%hitting%'; Chili Davis|44 Victor Rodriguez|57 OR sqlite> SELECT Coach.name, Coach.number FROM Coach, Player WHERE Player.team = Coach.team AND Player.name="Hanley Ramirez" AND Coach.title LIKE '%hitting%'; Chili Davis|44 Victor Rodriguez|57 6/19/2025 (c) 2013 RIT Dept. of Software Engineering 31