Northwind2003 database 11 Aug 201411. Sakila database 11 Aug 201422.

Slides:



Advertisements
Similar presentations
CC SQL Utilities.
Advertisements

SQL This presentation will cover: A Brief History of DBMS View in database MySQL installation.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
8 June Single table database in normal form Fields and records Normal form 1.Header in the first line 2.Same content for every field 3.Each record.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Oracle Data Definition Language (DDL)
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
Copyright © Curt Hill SQL The Data Definition Language.
CSCI 6962: Server-side Design and Programming
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
ASP.NET Programming with C# and SQL Server First Edition
10 May Microsoft Access 2010 Relational databases’ program Part of the Microsoft Office package Administer relational database Update database through.
MySQL. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn The main subsystems in MySQL architecture The different storage.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Analyzing Data For Effective Decision Making Chapter 3.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Introduction to MySQL Lab no. 10 Advance Database Management System.
5 Aug Microsoft Access 2010 Relational databases’ program Part of the Microsoft Office package Administer relational database Update database through.
Excel Project 2 Formulas, Functions, and Formatting.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Concepts of Database Management Seventh Edition
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 5 MYSQL Database. Introduction to MYSQL MySQL is the world's most popular open-source database. Open source means that the source code, the programming.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Lecture 8 – SQL Joins – assemble new views from existing tables INNER JOIN’s The Cartesian Product Theta Joins and Equi-joins Self Joins Natural Join.
Access Queries Agenda 6/16/14 Review Access Project Part 1, answer questions Discuss queries: Turning data stored in a database into information for decision.
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
3 A Guide to MySQL.
Understanding SQL Statements
Relational Database Design
Database application MySQL Database and PhpMyAdmin
Chapter 7 Working with Databases and MySQL
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
SQL-1 Week 8-9.
Contents Preface I Introduction Lesson Objectives I-2
MySQL Database System Installation Overview SQL summary
Non-selection queries
Presentation transcript:

Northwind2003 database 11 Aug

Sakila database 11 Aug

3 MySQL server Relational database management program Administer relational database Update database information Extract information through queries Server-client architecture User authentication Competitors: Access, Oracle, PostgreSQL 3

11 Aug MySQL client Personal program to access MySQL Command line interface HeidiSQL Preconfigured portable version from course website 4

11 Aug Starting HeidiSQL 1. Uncompress it on your Desktop 2. Connect to alcor.inf.unibz.it 3. Type your unibz username and password To use it from outside unibz LAN, you need before to log in to VPN here Manually configuring HeidiSQL (not needed) Installing MySQL server on your computer (useful but not necessary) 5

11 Aug Using HeidiSQL Database structure in the left window Commands executed and errors in the log window below Queries can be written in the Query tab and executed pressing F9 or Highlighting some commands and pressing F1 activates the SQL help 6

11 Aug Using HeidiSQL USE {database}; or click in the left window You must have appropriate privileges: GRANT SELECT GRANT INSERT GRANT UPDATE GRANT DELETE GRANT ALTER No way to undo your changes!!! ROLLBACK; command does not work on most MySQL tables 7

Selection query 11 Aug A question which produces a temporary table SELECT fields FROM table; SELECT fields FROM table WHERE condition ORDER BY field ASC|DESC; Mathematical operations AND, OR, NOT and parentheses Virtual field: expression AS name Views CREATE VIEW name AS selection query; DROP VIEW name;

Selection query 11 Aug mathematical operators + - * / and comparisons = = <> ROUND( ), ABS( ), EXP( ), SQRT( ), LOG( ) condition1 AND condition2, condition1 OR condition2, NOT condition field BETWEEN value1 AND value2 IS NULL, IS NOT NULL field IN (list) field LIKE expression containing % or _ CURDATE(), DATE_ADD(date, INTERVAL number DAY|MONTH|YEAR) YEAR(date), MONTH(date), DAY(date) DATEDIFF(date2,date1) To get difference in years: Approximate: ROUND(DATEDIFF(date2,date1)/365.25) Exact: YEAR(date2) - YEAR(date1) - ( DATE_FORMAT( date2, '%m%d' ) < DATE_FORMAT( date1, '%m%d' ) )

Joins 11 Aug Inner join SELECT fields FROM table1 INNER JOIN table2 ON field1 = field2; Names containing spaces must be enclosed by grave accent ` Values enclosed instead by apostrophe ’ Ambiguous field names use table.field table AS shortname from now on you must use nickname Difference between WHERE and ON Cross join Multiple inner joins

Summary query 11 Aug aggregates the records based on a GROUP BY instruction and returns one record per distinct value of GROUP BY fields If no GROUP BY is inserted, it aggregates everything SELECT function(field), grouping fields FROM tables with inner joins GROUP BY field; function is an aggregating function: Sum(field), Avg(field), Max(field), Min(field) Count(*), Count(DISTINCT field)

Summary query 11 Aug Conditions WHERE condition filters (and is written) before aggregation and thus must be used on fields which disappears after aggregation HAVING condition filters (and is written) after aggregation and thus must be used on aggregating functions fields which exist before and after aggregation, such as grouping fields, can be used in both conditions equivalently Do not select extra fields in summary queries!

Modifying data 11 Aug Using HeidiSQL graphical interface TRUNCATE table; DELETE FROM table WHERE condition; UPDATE table SET field = value WHERE condition; INSERT INTO table (fields) VALUES (values), …, (values); Exporting text data Fields’ delimiter Values’ encloser Importing text data Prepare structure before 13

Field types 11 Aug INT -2 billions to 2 billions TINYINT 0 or 1 DECIMAL(total number of digits, number of decimal digits) FLOAT non-exact real number CHAR (number of characters) fixed length text VARCHAR(maximum number of characters) variable length text TEXT very long text up to 60,000 characters ENUM( value, …, value ) Pay attention to numbers DATE time is supposed to be midnight, DATETIME Options NOT NULL, AUTO_INCREMENT, UNIQUE, DEFAULT default value, INDEX Primary key automatically has UNIQUE and NOT NULL and is an index Numerical codes are not numbers!

Table 11 Aug CREATE TABLE table ( field field-type options, …, PRIMARY KEY (field), INDEX (field), CHECK (condition) ); DROP TABLE table; ALTER TABLE table ADD field field-type options; ALTER TABLE table DROP field; ALTER TABLE table ADD PRIMARY KEY field; ALTER TABLE table DROP PRIMARY KEY; Using MySQL graphical interface Steal code from another table

 Create a blank database ◦ Build the tables  Start from the tables on the “1” side  Put appropriate types  Put appropriate primary key ◦ Check the structure ◦ Fill in the tables 16 Home exercise: Your library

 Queries ◦ Build a query to show book title, author surname, publishing year and author birth date ◦ Build a query to show book title, author surname and publishing date only for German and French authors.  Do not rewrite a new one. Modify easily the previous one adding another field with a condition and hiding it ◦ Build a query to show book title, author surname and publishing date only for those book published before  Do not rewrite a new one. Modify the first one. 17 Home exercise : Your library

 Exercises ◦ Is there the book TITLE? ◦ Is there a book TITLE published after 1/1/2000? ◦ Which books AUTHOR has published?  Improvements ◦ Put NOT NULL for appropriate fields ◦ Insert check constraints for appropriate fields ◦ Build a structure for predefined values lists where appropriate 18 Home exercise : Your library

 Advanced queries. Build a query which: ◦ shows book title, author surname and publishing year only for those authors born before a date invented by you. ◦ shows book title, author surname and the age of the author when the book was published. ◦ counts the books for every author. ◦ calculates the average publishing year of each author ◦ calculates the average publishing year of each author considering only German and English authors. 19 Home exercise : Your library

 Build a blank database ◦ Build the tables  Start from the tables on the “1” side  Put appropriate types  Put appropriate primary keys ◦ Check the structure ◦ Fill in the tables 20 Home exercise : students and exams

 Queries ◦ Build a query which displays, for every student, the list of his passed exams. ◦ Build a query which displays the list of passed exams and students’ last names, considering only who got a laude. ◦ Build a query which displays the student number (ordered from lowest to highest) of students who passed computer science. 21 Home exercise : students and exams

◦ Expand the database inserting information about professors and their exams  Many to many relation  another extra table ◦ Put NOT NULL for appropriate fields ◦ Insert check constraints for appropriate fields ◦ Build a structure for predefined values lists where appropriate 22 Home exercise : students and exams

 Advanced queries. Build a query which: ◦ shows the list of courses of professor Coletti. ◦ shows the list of exams of professor Coletti with the average grade that students obtain in the exam (considering, obviously, only the passed attempts) ◦ shows the list of professor Coletti’s exams with the number of students who got more that Home exercise : students and exams