Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS1222 Using Relational Databases and SQL

Similar presentations


Presentation on theme: "CS1222 Using Relational Databases and SQL"— Presentation transcript:

1 CS1222 Using Relational Databases and SQL
10/28/2019 CS Using Relational Databases and SQL Introduction Daniel Firpo Slides Prepared by Randy Moss Department of Computer Science California State University, Los Angeles

2 10/28/2019 Introduction

3 What is a database? A large, integrated collection of data Bank
10/28/2019 What is a database? A large, integrated collection of data Bank Company E-commerce Government University ………. 1. Introduction CS1222-Fall2019

4 Why use a database? Efficient data management access
10/28/2019 Why use a database? Efficient data management access Concurrent access and crash recovery Data administration Data integrity and security Data independence Reduced application development time 1. Introduction CS1222-Fall2019

5 Database models Physical model Logical model
10/28/2019 Database models Physical model How data is stored on a disk Logical model How data is organized Examples NoSQL Key-value pair Relational A set of concepts to describe the structure of a database, and certain constraints that the database should obey. 1. Introduction CS1222-Fall2019

6 Relational model Most popular relational DBMS
10/28/2019 Relational model Most popular relational DBMS Oracle, Postgres, MySQL, SQL Server, Access, and more How do Relational DBs store data? Tables! 1. Introduction CS1222-Fall2019

7 Relational Database Concepts: Table
10/28/2019 Relational Database Concepts: Table Field (column, Attribute) Table (Relation) Table: Titles Record (tuple, row) 1. Introduction CS1222-Fall2019

8 Relational Database Concepts
10/28/2019 Relational Database Concepts Candidate Key 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 CS1222-Fall2019

9 Relational Database Concepts
10/28/2019 Relational Database Concepts Candidate keys titleID, Title, UPC Primary key Any ONE of the candidate keys 1. Introduction CS1222-Fall2019

10 Data type Determine what kind of data a field can store
10/28/2019 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 CS1222-Fall2019

11 Schema “Definition” of a database Names of the tables
10/28/2019 Schema “Definition” of a database Names of the tables Attributes and attribute types in each table Constraints on each tables Dependencies between tables 1. Introduction CS1222-Fall2019

12 Introduction to SQL Structured Query Language Open ANSI standard
10/28/2019 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 CS1222-Fall2019

13 What Does SQL Do? Views information from relational database
10/28/2019 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 CS1222-Fall2019

14 SQL queries Basic format: If you select ALL attributes of a table
10/28/2019 SQL queries Basic format: 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 CS1222-Fall2019

15 SQL examples List all the attributes of all titles
10/28/2019 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 CS1222-Fall2019

16 10/28/2019 Using MySQL

17 2. Connect to the MySQL server
10/28/2019 2. Connect to the MySQL server $mysql –p You will be asked to input the password. The password is the original password assigned to you, not the password you just changed to. Change your password mysql> set password=PASSWORD(“new password”); $mysql –u username –p 1. Introduction CS1222-Fall2019

18 Run script files You’ll use four script files
10/28/2019 Run script files You’ll use four script files Lyric.sql: mostly for your labs Books.sql: mostly for your homework Orders.sql and Sailors.sql: mostly for exams These four files are used to create tables in your database 1. Introduction CS1222-Fall2019

19 Some MySQL commands Help Reconnect to the server Display sever info
10/28/2019 Some MySQL commands Help ? or \h or help; Reconnect to the server Connect; Display sever info Status Quit MySQL \q or quit; or exit; 1. Introduction CS1222-Fall2019

20 Some MySQL commands Show databases use database Show tables
10/28/2019 Some MySQL commands Show databases Show databases; use database Use dbname; Show tables Show tables; Show table schema Desc tablename 1. Introduction CS1222-Fall2019


Download ppt "CS1222 Using Relational Databases and SQL"

Similar presentations


Ads by Google