Databases CSCI 201 Principles of Software Development

Similar documents
SQL CSCI 201 Principles of Software Development

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

Chapter 4: SQL Basics

Networks and Web for Health Informatics (HINF 6220)

Data Base Concepts. Course Guide 2

DATABASES SQL INFOTEK SOLUTIONS TEAM

Using Relational Databases for Digital Research

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

Draft. Students Table. FName LName StudentID College Year. Justin Ennen Science Senior. Dan Bass Management Junior

Database Systems. S. Adams. Dilbert. Available: Hans-Petter Halvorsen

A practical introduction to database design

MySQL Introduction. By Prof. B.A.Khivsara

Referential integrity

Database. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

Databases and SQL Lab EECS 448

GlobAl EDITION. Database Concepts SEVENTH EDITION. David M. Kroenke David J. Auer

SQL Commands & Mongo DB New Syllabus

Database Systems CSE 414

Accessing databases in Java using JDBC

Database Systems CSE 414

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Review. Objec,ves. Example Students Table. Database Overview 3/8/17. PostgreSQL DB Elas,csearch. Databases

CSC 215 PROJECT 2 DR. GODFREY C. MUGANDA

Abstract Classes Interfaces CSCI 201 Principles of Software Development

Abstract Classes Interfaces CSCI 201 Principles of Software Development

Introduction to Database Systems CSE 444. Lecture 1 Introduction

CSC 337. Relational Databases and SQL. Rick Mercer

Introduction to Database S ystems Systems CSE 444 Lecture 1 Introduction CSE Summer

CMPT 354: Database System I. Lecture 2. Relational Model

In This Lecture. SQL Data Definition SQL SQL. Non-Procedural Programming. Notes. Database Systems Lecture 5 Natasha Alechina

DATABASE PART 2. Components and Functions

SQL DDL. Intro SQL CREATE TABLE ALTER TABLE Data types Service-based database in Visual Studio Database in PHPMyAdmin

Create a simple database with MySQL

Introduction to Database Systems CSE 344

Introduction to Database Systems CSE 344

Lecture 8. Database vs. Files SQL (I) Introduction to SQL database management systems (DBMS)

COP4540 TUTORIAL PROFESSOR: DR SHU-CHING CHEN TA: H S IN-YU HA

MySQL for Developers Ed 3

Data, Databases, and DBMSs

MySQL. A practical introduction to database design

BIS Database Management Systems.

DATABASE SYSTEMS. Introduction to MySQL. Database System Course, 2016

MIS Database Systems.

MySQL for Developers Ed 3

Advanced SQL. Nov 21, CS445 Pacific University 1

Introduction to the Structured Query Language [ SQL ] (Significant Concepts)

Introduction to Database Systems

CS40 Exam #2 November 14, 2001

CS 338 Databases and Database Users INTRODUCTION

COMP519: Web Programming Autumn 2015

Working with Databases and Java

Course: Database Management Systems. Lê Thị Bảo Thu

1.8 Database and data Data Definition Language (DDL) and Data Manipulation Language (DML)

CS143: Relational Model

Structured Query Language

SQL Server and SQL Structured Query Language

Chapter 13 : Informatics Practices. Class XI ( As per CBSE Board) SQL Commands. New Syllabus Visit : python.mykvs.in for regular updates

Manual Trigger Sql Server 2008 Examples Insert Update

DATABASE SYSTEMS. Introduction to MySQL. Database System Course, 2018

Chapter 9: Working with MySQL

What data persistence means? We manipulate data (represented as object state) that need to be stored

Java Persistence API (JPA)

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)


CSC 4710 / CSC 6710 Database Systems. Rao Casturi

Databases (MariaDB/MySQL) CS401, Fall 2015

CGS 3066: Spring 2017 SQL Reference

CS313D: ADVANCED PROGRAMMING LANGUAGE

Assertions, Views, and Programming. CS157A Chris Pollett Oct. 31, 2005.

tablename ORDER BY column ASC tablename ORDER BY column DESC sortingorder, } The WHERE and ORDER BY clauses can be combined in one

SEF DATABASE FOUNDATION ON ORACLE COURSE CURRICULUM

Chapter 6. Foundations of Business Intelligence: Databases and Information Management VIDEO CASES

Today Learning outcomes LO2

CSCI 585- Database Systems Spring 2008 Homework Assignment 2 Due: Tuesday, April

CS2300: File Structures and Introduction to Database Systems

DATABASE SYSTEMS. Introduction to MySQL. Database System Course, 2016

FIT 100 More Microsoft Access and Relational Databases Creating Views with SQL

CSE 303: Database. Teaching Staff. Lecture 01. Lectures: 1 st half - from a user s perspective. Lectures: 2 nd half - understanding how it works

Get Table Schema In Sql Server 2008 To Add Column If Not Exists >>>CLICK HERE<<<

Relational databases and SQL

Let's Play... Try to name the databases described on the following slides...

Introduction to Databases and SQL

EE221 Databases Practicals Manual

Database Application Development

CSE 544 Principles of Database Management Systems

Exploring Microsoft Office Access Chapter 2: Relational Databases and Multi-Table Queries

Previously everyone in the class used the mysql account: Username: csci340user Password: csci340pass

Unit 27 Web Server Scripting Extended Diploma in ICT

Sql 2008 Copy Table Structure And Database To

9/8/2018. Prerequisites. Grading. People & Contact Information. Textbooks. Course Info. CS430/630 Database Management Systems Fall 2018

PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008.

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

Spring % of course grade

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2

Supported Platforms for Alfresco Workdesk 4.x

What is SQL? Toolkit for this guide. Learning SQL Using phpmyadmin

Export Database Diagram Sql Server 2005 Pdf

Sqlite Database Programming For Xamarin Cross Platform C Database Development For Ios And Android Using Sqlitexm

CS 564: DATABASE MANAGEMENT SYSTEMS

Relational Database Systems I. Introduction

Transcription:

Databases CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu

Outline Databases SQL Try It! USC CSCI 201L

Databases Database systems store data and provide a means of accessing, updating, manipulating, and analyzing data Databases are stored in files on a file system, but they are arranged in a manner that allows for fast queries and updates A Database Management System (DBMS) is designed for programmers, not casual users MySQL PostgreSQL Oracle Microsoft SQL Server IBM DB2 Apache Hadoop MongoDB Firebase USC CSCI 201L 3/14

Relational Databases Relational database management systems (RDBMS) provide three things Structure the representation of the data Integrity constraints on the data Language means for accessing and manipulating data OverallGrades prefix num fname lname lettergrade CSCI 103 Sheldon Cooper A CSCI 104 Howard Wolowitz A- CSCI 201 Leonard Hofstadter A CSCI 201 Howard Wolowitz B EE 101 Howard Wolowitz B- Tables are called relations Columns are called attributes Rows are called tuples Connections are called relationships USC CSCI 201L 4/14

Relational Databases OverallGrades prefix num fname lname lettergrade CSCI 103 Sheldon Cooper A Non-normalized CSCI 104 Howard Wolowitz A- CSCI 201 Leonard Hofstadter A CSCI 201 Howard Wolowitz B EE 101 Howard Wolowitz B- Class classid prefix num 1 CSCI 103 2 CSCI 104 3 CSCI 201 4 EE 101 Normalized Grades gradeid classid studentid lettergrade 1 1 1 A 2 2 3 A- 3 3 2 A 4 3 3 B 5 4 3 B- Student studentid fname lname 1 Sheldon Cooper 2 Leonard Hofstadter 3 Howard Wolowitz 4 Rajesh Koothrappali USC CSCI 201L 5/14

Primary and Foreign Keys A primary key is a column (or a combination of multiple columns) in a table that provides a unique reference to a row in the table A foreign key is a link between two tables that uniquely identifies a row in another table Class classid prefix num 1 CSCI 103 2 CSCI 104 3 CSCI 201 4 EE 101 5 EE 102 Grades gradeid classid studentid lettergrade 1 1 1 A 2 2 3 A- 3 3 2 A 4 3 3 B 5 5 3 B- Student studentid fname lname 1 Sheldon Cooper 2 Leonard Hofstadter 3 Howard Wolowitz 4 Rajesh Koothrappali 6/14

Outline Databases SQL Try It!

SQL The Structured Query Language (SQL) is the primary language supported by DBMSs for accessing and manipulating data Some MySQL SQL statements you should know SHOW CREATE DATABASE USE CREATE TABLE INSERT UPDATE SELECT DELETE DROP If you are not familiar with SQL, there are many good tutorials online and our textbook has a good chapter reference as well USC CSCI 201L 8/14

SQL Scripts After installing a DBMS, you will be able to run SQL scripts SQL scripts are files that contain a collection of SQL statements that can be used for recreating databases and populating them with initial or testing data This is often used in the testing phase of software engineering to test different scenarios without requiring the QA engineers to insert all of the data manually USC CSCI 201L 9/14

Sample Script 1 DROP DATABASE if exists StudentGrades; 2 CREATE DATABASE StudentGrades; 3 USE StudentGrades; 4 CREATE TABLE Student ( 5 studentid int(11) primary key not null auto_increment, 6 fname varchar(50) not null, 7 lname varchar(50) not null 8 ); 9 INSERT INTO Student (fname, lname) VALUES ('Sheldon', 'Cooper'); 10 INSERT INTO Student (fname, lname) VALUES ('Leonard', 'Hofstadter'); 11 CREATE TABLE Class ( 12 classid int(11) primary key not null auto_increment, 13 prefix varchar(5) not null, 14 num int(4) not null 15 ); 16 INSERT INTO Class (prefix, num) VALUES ('CSCI', 103); 17 INSERT INTO Class (prefix, num) VALUES ('CSCI', 104); 18 CREATE TABLE Grade ( 19 gradeid int(11) primary key not null auto_increment, 20 classid int(11) not null, 21 studentid int(11) not null, 22 lettergrade varchar(2) not null, 23 FOREIGN KEY fk1(classid) REFERENCES class(classid), 24 FOREIGN KEY fk2(studentid) REFERENCES student(studentid) 25 ); 26 INSERT INTO Grade (studentid, classid, lettergrade) VALUES (1, 1, 'A'); 27 INSERT INTO Grade (studentid, classid, lettergrade) VALUES (1, 2, 'A'); 28 INSERT INTO Grade (studentid, classid, lettergrade) VALUES (2, 1, 'A'); 29 INSERT INTO Grade (studentid, classid, lettergrade) VALUES (2, 2, B'); Class classid prefix num 1 CSCI 103 2 CSCI 104 Grade studentid fname lname 1 Sheldon Cooper 2 Leonard Hofstadter gradeid classid studentid lettergrade 1 1 1 A 2 2 1 A 3 1 2 A 4 2 2 B Student USC CSCI 201L 10/14

SQL Visualization Tools A visualization tool connects to a database and allows execution of SQL statements The tool then will graphically display the results Free MySQL Clients Command line client (Windows, Mac, Linux) MySQL Workbench (Windows, Mac, Linux) Sequel Pro (Mac) Toad for MySQL (Windows) USC CSCI 201L 11/14

Executing SQL There are a few ways to execute SQL statements, which typically depend on the DBMS We often want to be able to access databases from within programs though This can be to insert, update, delete, or query the data The Java Database Connectivity (JDBC) drivers allow us to embed SQL in our Java code and execute those statements on a database programmatically USC CSCI 201L 12/14

Outline Databases SQL Try it! USC CSCI 201L

SQL Write SQL code to create the following database Class classid prefix num 1 CSCI 103 2 CSCI 104 3 CSCI 201 4 EE 101 5 EE 102 Grades gradeid classid studentid lettergrade 1 1 1 A 2 2 3 A- 3 3 2 A 4 3 3 B 5 5 3 B- Student studentid fname lname 1 Sheldon Cooper 2 Leonard Hofstadter 3 Howard Wolowitz 4 Rajesh Koothrappali USC CSCI 201L 14/14