Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.

Slides:



Advertisements
Similar presentations
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Advertisements

Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
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.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
CS 142 Lecture Notes: Relational DatabasesSlide 1 Relation (Table) namebirthgpagrad Anderson Jones Hernandez
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
Informatiesystemen in de Bouw 7M711 Joran Jessurun en Jos van Leeuwen Week 3.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
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.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
CSC 2720 Building Web Applications Database and SQL.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Database Systems Lecture 5 Natasha Alechina
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Introduction to SQL Steve Perry
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
CSC 2720 Building Web Applications Database and SQL.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
CS 142 Lecture Notes: Relational DatabasesSlide 1 Relation (Table) namebirthgpagrad Anderson Jones Hernandez
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.
DAY 14: MICROSOFT ACCESS – CHAPTER 1 Madhuri Siddula October 1, 2015.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
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.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Working with MySQL A290/A590, Fall /07/2014.
Databases and SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Introduction to Database Programming with Python Gary Stewart
Web Systems & Technologies
Logical DB Design: ER to Relational
CS320 Web and Internet Programming SQL and MySQL
Relation (Table) Row/Tuple/Record Column/Attribute/Field name birth
CS1222 Using Relational Databases and SQL
Relation (Table) Row/Tuple/Record Column/Attribute/Field name birth
Model for Student Table
CS1222 Using Relational Databases and SQL
CMPT 354: Database System I
CS 142 Lecture Notes: Relational Databases
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS3220 Web and Internet Programming SQL and MySQL
Model for Student Table
Charles Severance Single Table SQL.
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
Presentation transcript:

Introduction to Databases & SQL Ahmet Sacan

What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases

DB Definitions Relational database: collection of tables (also called relations) Database Management System (DBMS): a software that is used to create, access and maintain a database; e.g., mysql, sqlite, oracle, sql server. Table: Collection of rows (also called tuples or records). Each row in a table contains a set of columns (also called fields or attributes). Each column has a type: – String: VARCHAR(20) – Integer: INTEGER – Floating-point: FLOAT, DOUBLE – Date/time DATE, TIME, DATETIME Primary key: provides a unique identifier for each row (optional). Schema: the structure of the database tables – The table name – The names and types of its columns – Various optional additional information (defaults, constraints, etc.) Definitions and Examples adapted from: ouster/cgi-bin/cs142-spring12/lecture.php?topic=sql

SQL SQL = “Structured Query Language” – Non-procedural – Set-oriented – Relationally complete – Functionally incomplete Four main types of queries: – Insert, Delete, Select, Update

Create/drop table Syntax: – Create a table for the students: CREATE TABLE students ( id INT AUTO_INCREMENT, name VARCHAR(30), birth DATE, gpa FLOAT, grad INT, PRIMARY KEY(id)); Drop table: DROP TABLE students;

Insert/Delete Add rows to the students table: INSERT INTO students(id,name, birth, gpa, grad) VALUES (1,'Anderson', ' ', 3.9, 2009); INSERT INTO students(id,name, birth, gpa, grad) VALUES (2,'Jones', ' ', 2.4, 2012); INSERT INTO students(id,name, birth, gpa, grad) VALUES (3,'Hernandez', ' ', 3.1, 2011); INSERT INTO students(id,name, birth, gpa, grad) VALUES (4,'Chen', ' ', 3.2, 2011); Delete row(s): DELETE FROM students;

Select Queries 3 main elements: – What you want – Where it is found – How you want it filtered Show entire contents of a table: 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 |

Select Show just a few columns from a table: SELECT name, gpa FROM students; | name | gpa | | Anderson | 3.9 | | Jones | 2.4 | | Hernandez | 3.1 | | Chen | 3.2 | Filtering: only get a subset of the rows: SELECT name, gpa FROM students WHERE gpa > 3.0; | name | gpa | | Anderson | 3.9 | | Hernandez | 3.1 | | Chen | 3.2 |

Select Sorting: 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 | Limiting: only get a certain number of rows: SELECT name, gpa FROM students LIMIT 0,2; | name | gpa | | Anderson | 3.9 | | Jones | 2.4 |

Update / Delete Update: UPDATE students SET gpa = 2.6, grad = 2013 WHERE id = 2; Delete: DELETE FROM students WHERE id = 2;

Joins Join: a query that merges the contents of 2 or more tables, displays information from the results. Join example: many-to-one relationship Students have advisors; add new table describing faculty | id | name | title | | 1 | Fujimura | assocprof | | 2 | Bolosky | prof |

Join example: many-to-one relationship Add new column advisor_id to the students table. This is a foreign key | id | name | birth | gpa | grad | advisor_id | | 1 | Anderson | | 3.9 | 2009 | 2 | | 2 | Jones | | 2.4 | 2012 | 1 | | 3 | Hernandez | | 3.1 | 2011 | 1 | | 4 | Chen | | 3.2 | 2011 | 1 | Perform the join query. 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 |

Join example: many-to-many relationship Courses: students take many courses, courses have many students Add new table describing courses: | id | number | name | quarter | | 1 | CS142 | Web stuff | Winter 2009 | | 2 | ART101 | Finger painting | Fall 2008 | | 3 | ART101 | Finger painting | Winter 2009 | | 4 | PE204 | Mud wrestling | Winter 2009 | Create a “join table” courses_students describing which students took which courses | course_id | student_id | | 1 | 1 | | 3 | 1 | | 4 | 1 | | 1 | 2 | | 2 | 2 | | 1 | 3 | | 2 | 4 | | 4 | 4 |

Join example: many-to-many relationship Find all students who took a particular course: SELECT s.name, c.quarter FROM students s, courses c, courses_students cs WHERE c.number = 'ART101' AND c.id = cs.course_id AND cs.student_id = s.id; | name | quarter | | Jones | Fall 2008 | | Chen | Fall 2008 | | Anderson | Winter 2009 |

Additional Database Features Indexes: used to speed up searches Transactions: used to group operations together to provide predictable behavior even when there are concurrent operations on the database. Views: a virtual table for results of a stored query Procedures: a set of sql statements stored in the database