CS 142 Lecture Notes: Relational DatabasesSlide 1 Relation (Table) namebirthgpagrad Anderson1987-10-223.92009 Jones1990-4-162.42012 Hernandez1989-8-123.12011.

Slides:



Advertisements
Similar presentations
© Abdou Illia MIS Spring 2014
Advertisements

Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Introduction to Relational Databases Obtained from Portland State University.
Cs3431 Constraints Sections 6.1 – 6.5. cs3431 Example CREATE TABLE Student ( sNum int, sName varchar (20), prof int, CONSTRAINT pk PRIMARY KEY (snum),
Structured Query Language - SQL Carol Wolf Computer Science.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
Mid-term Exam Answer Keys Week 7 Spring I. Multiple Choices Questions Each may have more than one answer (6 x 4 = 24 points total)
Structured Query Language Review ISYS 650. Language Overview Three major components: –Data definition language, DDL Create, Drop and Alter Tables or Views.
CS 142 Lecture Notes: Relational DatabasesSlide 1 Relation (Table) namebirthgpagrad Anderson Jones Hernandez
1 Query Languages: How to build or interrogate a relational database Structured Query Language (SQL)
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
Student(sid, name, addr, age, GPA) Class(dept, cnum, sec, unit, title, instructor) Enroll(sid, dept, cnum, sec) siddeptcnumsec 301CS CS AT00000.
Database Management System LICT 3011 Eyad H. Elshami.
Introduction to Information and Computer Science
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
CSC 405: Web Application And Engineering II7.1 Database Programming with SQL Aggregation and grouping with GROUP BY Aggregation and grouping with GROUP.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
CS 3630 Database Design and Implementation. Database Schema Branch (Bno…) Staff (Sno…Bno) Owner (Ono…) PropertyForRent (Pno…Ono) Renter (Rno…) Viewing.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
Database Indexing 1 After this lecture, you should be able to:  Understand why we need database indexing.  Define indexes for your tables in MySQL. 
1 SQL Insert Update Delete Create table Alter table.
The Relational Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
SQL Miscellaneous Topics. Views A database view is: – a virtual or logical table based on a query. – a stored query. CREATE VIEW viewname AS query; –CREATE.
Lectures 2&3: Introduction to SQL. Lecture 2: SQL Part I Lecture 2.
CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, TEXT ERROR Nationality char (30) NULL, Birthdate numeric (4,0) NULL,
SQL constrains and keys. SORTED RESULTS Sort the results by a specified criterion SELECT columns FROM tables WHERE predicates ORDER BY column ASC/DESC;
Working with MySQL A290/A590, Fall /07/2014.
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
Spring 2011 ITCS3160: Database Design and Implementation Hands-on Learning.
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
 Database – collection of persistent data  Database Management System (DBMS) – software system that supports creation, population, and querying of a.
Logical DB Design: ER to Relational
Referential Integrity MySQL
File Processing with Excel’s List
Relation (Table) Row/Tuple/Record Column/Attribute/Field name birth
Lecture#7: Fun with SQL (Part 2)
Referential Integrity
Relation (Table) Row/Tuple/Record Column/Attribute/Field name birth
The Relational Model Relational Data Model
Model for Student Table
MySQL Tables and Relations 101
Referential Integrity
File Processing with Excel’s List
CMPT 354: Database System I
Lectures 3: Introduction to SQL 2
CS 142 Lecture Notes: Relational Databases
Model for Student Table
SQL: Structured Query Language
SQL: Structured Query Language
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
Presentation transcript:

CS 142 Lecture Notes: Relational DatabasesSlide 1 Relation (Table) namebirthgpagrad Anderson Jones Hernandez Chen VARCHAR(30)DATEFLOATINT Column/Attribute/FieldRow/Tuple/Record Column Types

CS 142 Lecture Notes: Relational DatabasesSlide 2 Primary Key idnamebirthgpagrad 14Anderson Jones Hernandez Chen INTVARCHAR(30)DATEFLOATINT Unique For Each Row

CS 142 Lecture Notes: Relational DatabasesSlide 3 Basic Table Operations CREATE TABLE students ( id INT AUTO_INCREMENT, name VARCHAR(30), birth DATE, gpa FLOAT, grad INT, PRIMARY KEY(id)); INSERT INTO students(name, birth, gpa, grad) VALUES ('Anderson', ' ', 3.9, 2009); INSERT INTO students(name, birth, gpa, grad) VALUES ('Jones', ' ', 2.4, 2012); DELETE FROM students WHERE name='Anderson'; DROP TABLE students;

CS 142 Lecture Notes: Relational DatabasesSlide 4 Query: Display Entire Table idnamebirthgpagrad 1Anderson Jones Hernandez Chen SELECT * FROM students; | id | name | birth | gpa | grad | | 1 | Anderson | | 3.9 | 2009 | | 2 | Jones | | 2.4 | 2012 | | 3 | Hernandez | | 3.1 | 2011 | | 4 | Chen | | 3.2 | 2011 |

CS 142 Lecture Notes: Relational DatabasesSlide 5 Query: Select Columns idnamebirthgpagrad 1Anderson Jones Hernandez Chen SELECT name, gpa FROM students; | name | gpa | | Anderson | 3.9 | | Jones | 2.4 | | Hernandez | 3.1 | | Chen | 3.2 |

CS 142 Lecture Notes: Relational DatabasesSlide 6 Query: Filter Rows idnamebirthgpagrad 1Anderson Jones Hernandez Chen SELECT name, gpa FROM students WHERE gpa > 3.0; | name | gpa | | Anderson | 3.9 | | Hernandez | 3.1 | | Chen | 3.2 |

CS 142 Lecture Notes: Relational DatabasesSlide 7 Query: Sort Output idnamebirthgpagrad 1Anderson Jones Hernandez Chen SELECT gpa, name, grad FROM students WHERE gpa > 3.0 ORDER BY gpa DESC; | gpa | name | grad | | 3.9 | Anderson | 2009 | | 3.2 | Chen | 2011 | | 3.1 | Hernandez | 2011 |

CS 142 Lecture Notes: Relational DatabasesSlide 8 Update Value(s) idnamebirthgpagrad 1Anderson Jones Hernandez Chen UPDATE students SET gpa = 2.6, grad = 2013 WHERE id = 2

CS 142 Lecture Notes: Relational DatabasesSlide 9 s.ids.names.births.gpas.grads.advisor_idp.idp.namep.title 1Anderson Fujimuraassocprof 1Anderson Boloskyprof 2Jones Fujimuraassocprof 2Jones Boloskyprof 3Hernandez Fujimuraassocprof 3Hernandez Boloskyprof 4Chen Fujimuraassocprof 4Chen Boloskyprof idnamebirthgpagradadvisor_id 1Anderson Jones Hernandez Chen Foreign Key SELECT s.name, s.gpa FROM students s, advisors p WHERE s.advisor_id = p.id AND p.name = 'Fujimura'; students advisors idnametitle 1Fujimuraassocprof 2Boloskyprof

CS 142 Lecture Notes: Relational DatabasesSlide 10 s.ids.names.births.gpas.grads.advisor_idp.idp.namep.title 1Anderson Fujimuraassocprof 1Anderson Boloskyprof 2Jones Fujimuraassocprof 2Jones Boloskyprof 3Hernandez Fujimuraassocprof 3Hernandez Boloskyprof 4Chen Fujimuraassocprof 4Chen Boloskyprof idnametitle 1Fujimuraassocprof 2Boloskyprof idnamebirthgpagradadvisor_id 1Anderson Jones Hernandez Chen SELECT s.name, s.gpa FROM students s, advisors p WHERE s.advisor_id = p.id AND p.name = 'Fujimura'; students advisors

CS 142 Lecture Notes: Relational DatabasesSlide 11 SELECT s.name, s.gpa FROM students s, advisors p WHERE s.advisor_id = p.id AND p.name = 'Fujimura'; | name | gpa | | Jones | 2.4 | | Hernandez | 3.1 | | Chen | 3.2 | idnamebirthgpagradadvisor_id 1Anderson Jones Hernandez Chen students advisors idnametitle 1Fujimuraassocprof 2Boloskyprof

CS 142 Lecture Notes: Relational DatabasesSlide 12 idnamebirthgpagrad 1Anderson Jones Hernandez Chen idnumbernamequarter 1CS142Web stuffWinter ART101Finger paintingFall ART101Finger paintingWinter PE204Mud wrestlingWinter 2009 course_idstudent_id students courses courses_students SELECT s.name, c.quarter FROM students s, courses c, courses_students cs WHERE c.id = cs.course_id AND s.id = cs.student_id AND c.number = 'ART101'; | name | quarter | | Jones | Fall 2008 | | Chen | Fall 2008 | | Anderson | Winter 2009 |

CS 142 Lecture Notes: Relational DatabasesSlide 13 idnamebirthgpagrad 1Anderson Jones Hernandez Chen idnumbernamequarter 1CS142Web stuffWinter ART101Finger paintingFall ART101Finger paintingWinter PE204Mud wrestlingWinter 2009 course_idstudent_id students courses courses_students SELECT s.name, c.quarter FROM students s, courses c, courses_students cs WHERE c.id = cs.course_id AND s.id = cs.student_id AND c.number = 'ART101'; | name | quarter | | Jones | Fall 2008 | | Chen | Fall 2008 | | Anderson | Winter 2009 |

CS 140 Lecture Notes: File SystemsSlide 14