Download presentation
Presentation is loading. Please wait.
1
CS1222 Using Relational Databases and SQL
3/27/2020 CS Using Relational Databases and SQL Introduction Huiping Guo Department of Computer Science California State University, Los Angeles
2
What is a database? A large, integrated collection of data Bank
Company E-commerce Government University ………. 1. Introduction
3
Why use a database? Efficient data management access
Concurrent access and crash recovery Data integrity and security Data administration Data independence Reduced application development time 1. Introduction
4
Database models Physical model Logical model
3/27/2020 Database models Physical model How data is stored on a disk Logical model How data is organized Three models Hierarchical Network Relational A set of concepts to describe the structure of a database, and certain constraints that the database should obey. 1. Introduction
5
Relational model Most popular relational DBMS
Oracle, Sybase, MySQL, SQL Server, Access In this model, a database is a collection of tables The tables are related to each other 1. Introduction
6
Relational Database Concepts: Table
Field (column, Attribute) Table (Relation) Table: Titles Record (tuple, row) 1. Introduction
7
Relational Database Concepts
Candidate Key Also called keys Uniquely identify a record No two rows have the same candidate key Maybe multiple candidate keys in a table Primary key Select a candidate key as the primary key Only one primary key in a table 1. Introduction
8
Relational Database Concepts
Candidate keys titleID, Title, UPC Primary key Any ONE of the candidate keys 1. Introduction
9
Data type Determine what kind of data a field can store
Common data types Text Numeric Byte integer, long integer, single, double, decimal date/time, boolean Special 1. Introduction
10
Schema “Definition” of a database To be covered in CS4222
Names of the tables Attributes and attribute types in each table Constraints on each tables Dependencies between tables To be covered in CS4222 1. Introduction
11
Introduction to SQL Structured Query Language Open ANSI standard
Supported by most databases Some variation in implementation A skill that is used by many people in many environments Programmers Database Administrators Managers 1. Introduction
12
What Does SQL Do? Views information from relational database
Single or Multiple Tables Tools to Calculate and Summarize Manipulates information in relational database Insert Records Update Records Delete Records Operates on entire recordset with single command Defines relational database Create Database, Tables, Primary and Foreign Keys 1. Introduction
13
SQL queries Basic format: If you select ALL attributes of a table
SELECT filed_name1, field_name2,… FROM table_name1, tabel_name2… [WHERE conditions] If you select ALL attributes of a table SELECT * FROM table_name [WHERE conditions] 1. Introduction
14
SQL examples List all the attributes of all titles
SELECT * FROM Titles List the title and upc of all titles SELECT title, upc List the title and upc of the titles in the ‘metal’ genre WHERE genre = ‘metal’ 1. Introduction
15
Using MySQL
16
Introduction to MySQL MySQL is a free client-server DBMS MySQL Sever
cs1.calstatela.edu MySQL client Graphical User Interface tool MySQL Workbench, MYSQL client… Command line Connect to the server directly under the command window SSH Secure Shell Client 1. Introduction
17
MySQL Workbench Minimum Requirements for Windows Download Workbench
Microsoft .NET Framework 4.5.2 Visual C++ Redistributable for Visual Studio 2019 Download Workbench Install 1. Introduction
18
MySQL Workbench for MAC
Please check the following link: 1. Introduction
19
Launch MySQL workbench
1. Introduction
20
Set up a new connection 1. Introduction Name the connection
Your assigned user name Your assigned user name Click here to enter your password 1. Introduction
21
Double click 1. Introduction
22
1. Introduction
23
Create tables in the Lyric database
Open lyric.sql posted on the class webpage Copy&paste the content of the file to the query window Run the queries 1. Introduction
24
Create tables in the Lyric database
Run the query 1. Introduction
25
1. Introduction
26
Design the following queries:
Find all the information of sales person Find the name and web address of all artists Find the names of all artists who are in Canada Find the titleIDs and the titles that are recorded in studio 1 Find the titles of all tracks on titleID 1 1. Introduction
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.