Lecture 1.21 SQL Introduction Steven Jones, Genome Sciences Centre.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Advertisements

Database Chapters.
A comparison of MySQL And Oracle Jeremy Haubrich.
Pertemuan ke 2 Tipe data & ERD Kurniawan Eka Permana.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
1 SQL (CSCE 330) Team Members Bushira Kiyemba La’Trice Johnson Curtis Merriweather.
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
SQL Basics+ Brandon Checketts. Why SQL? Structured Query Language Structured Query Language Frees programmers from dealing with specifics of data persistence.
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.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Lecture 9 – MYSQL and PHP (Part1) SFDV3011 – Advanced Web Development 1.
Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
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.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
LIS651 lecture 6 mySQL Thomas Krichel
Introduction to MySQL Lab no. 10 Advance Database Management System.
Introduction to Internet Databases MySQL Database System Database Systems.
CSC 2720 Building Web Applications Database and SQL.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
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.
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.
Most information comes from Chapter 3, MySQL Tutorial: 1 MySQL: Part.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Advanced Web 2012 Lecture 3 Sean Costain What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.
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,
Sql DDL queries CS 260 Database Systems.
Introduction to MySQL Lab no. 9 Advance Database Management System.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
CHAPTER 10 PHP MySQL Database
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Relational Databases and MySQL Charles Severance
Working with MySQL A290/A590, Fall /07/2014.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.
Introduction to Database Programming with Python Gary Stewart
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
CS320 Web and Internet Programming SQL and MySQL
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
MYSQL INTERVIEW QUESTIONS AND ANSWERS
Relational Databases and MySQL
ISC440: Web Programming 2 Server-side Scripting PHP 3
Database systems Lecture 2 – Data Types
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
Intro to Relational Databases
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
Chapter 4 Introduction to MySQL.
Data.
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
Presentation transcript:

Lecture 1.21 SQL Introduction Steven Jones, Genome Sciences Centre

Lecture 1.22 History of Relational Databases Relational databases Initially described by E.F. Codd from IBM in June, IBM developed a language to access the database called “Structured English Query Language” – SEQUEL – later called SQL. First commercial product developed by a small startup company called Oracle

Lecture 1.23 Salient Features of a Relational Database Data is held in tables.

Lecture 1.24 Relational Databases Oracle DB2 (IBM) PostgreSQL MySQL

Lecture 1.25 MySQL General Purpose Open Source RDBMS Optimized for speed, reliability and high-load Well supported and documented Easy to install, configure and manage Comes with many Linux distributions Widely used >10,000 server downloads per day Low cost of ownership

Lecture 1.26 High-Profile users of MySQL NASA Yahoo finance Slashdot.org, Freshmeat.net, Linux.com Nortel, Ericsson, Alcatel, Telia, Nokia Motorola Compaq Ensembl

Lecture 1.27 Accessible through many Programmable interfaces ADA C C++ LISP Delphi Dylan Guile JDBC MatLab ODBC Perl PHP Pike Python etc

Lecture 1.28 A typical Table mysql> select * From Scientist ; | Scientist_ID | Room | Phone | Last_Name | First_Name | | | 1 | H201 | | Harries | John | | | 2 | C405 | | Carter | Ross | | | 3 | C401 | NULL | Juriloff | Nancy | | | 4 | F301 | | Hawkins | Joyce | | rows in set (0.00 sec)

Lecture 1.29 Data Types Choosing the type of Date stored in each column is key to the utility and efficiency of your database Various data-types exist to store integer numbers, strings, time, date, binary objects (BLOBS).

Lecture Numeric Column Types TINYINT SMALLINT MEDIUM INT INT BIG INT FLOAT DOUBLE DECIMAL String Column Types CHAR VARCHAR TINYBLOB BLOB MEDIUM BLOB LONG BLOB TINYTEXT TEXT MEDIUMTEXT LONGTEXT Date and Time DATE TIME DATETIME TIMESTAMP YEAR

Lecture Different Data-Types Numeric Column Types TINYINT SMALLINT MEDIUM INT INT BIG INT FLOAT DOUBLE DECIMAL String Column Types CHAR VARCHAR TINYBLOB BLOB MEDIUM BLOB LONG BLOB TINYTEXT TEXT MEDIUMTEXT LONGTEXT Date and Time DATE TIME DATETIME TIMESTAMP YEAR

Lecture Querying the data mysql> select * FROM Scientist WHERE Last_Name="Harries"; | Scientist_ID | Room | Phone | Last_Name | First_Name | | | 1 | H201 | | Harries | John | | row in set (0.00 sec)

Lecture Inserting Data mysql> INSERT INTO Scientist (Room,Phone,Last_Name,First_Name) VALUES ('H234',' ','Michaels','James'); Query OK, 1 row affected (0.06 sec) mysql> select * FROM Scientist | Scientist_ID | Room | Phone | Last_Name | First_Name | | | 1 | H201 | | Harries | John | | | 2 | C405 | | Carter | Ross | | | 3 | C401 | NULL | Juriloff | Nancy | | | 4 | F301 | | Hawkins | Joyce | | | 5 | H234 | | Michaels | James | | rows in set (0.00 sec)

Lecture Editing Rows mysql> UPDATE Scientist SET ="jmtelus.net" WHERE Scientist_ID='5'; Query OK, 1 row affected (0.06 sec) ws matched: 1 Changed: 1 Warnings: 0 mysql> select * FROM Scientist ; | Scientist_ID | Room | Phone | Last_Name | First_Name | | | 1 | H201 | | Harries | John | | | 2 | C405 | | Carter | Ross | | | 3 | C401 | NULL | Juriloff | Nancy | | | 4 | F301 | | Hawkins | Joyce | | | 5 | H234 | | Michaels | James | jmtelus.net | rows in set (0.00 sec) mysql>

Lecture Exploring a Database mysql> SHOW TABLES ; | Tables_in_clone_db | | Clone | | Scientist | rows in set (0.00 sec) mysql> Describe Clone; | Field | Type | Null | Key | Default | Extra | | Clone_ID | int(10) unsigned | | PRI | NULL | auto_increment | | Requestor_ID | int(11) | | | 0 | | | Date_Received | date | | | | | | Date_Completed | date | YES | | NULL | | rows in set (0.01 sec)

Lecture Creating Tables CREATE TABLE Clone ( Clone_ID int(10) unsigned NOT NULL auto_increment PRIMARY KEY, Requestor_ID int(11) NOT NULL Date_Received date NOT NULL, Date_Completed date, ) Creating the “Clone” Table NOT NULL – This field cannot be empty Auto_increment – Automatically Generate a new clone_ID for each row added PRIMARY KEY – Creates an index for the table based on this value

Lecture The Clone Table mysql> select * FROM Clone ; | Clone_ID | Requestor_ID | Date_Received | Date_Completed | | 1 | 2 | | | | 2 | 2 | | | | 3 | 3 | | NULL | | 4 | 4 | | NULL | | 5 | 4 | | | | 6 | 4 | | NULL | rows in set (0.00 sec)

Lecture Goals Calculate the turnaround time on completed clones? What is the outstanding time on incomplete clones? Who has outstanding clones? Who has used the service the most?

Lecture Calculating turnaround time mysql> SELECT Clone_ID, Date_Received, (TO_DAYS(Date_Completed))- TO_DAYS(Date_Received) AS Turnaround FROM Clone WHERE Date_Completed IS NOT NULL ; | Clone_ID | Date_Received | Turnaround | | 1 | | 14 | | 2 | | 10 | | 5 | | 6 | rows in set (0.00 sec) Note the TO_DAYS function turns a date value into the number of DAYS since 1 st of Jan 0001.

Lecture Determining Outstanding Clones mysql> SELECT Clone_ID, Date_Received, (TO_DAYS(CURRENT_DATE))- TO_DAYS(Date_Received) AS Turnaround FROM Clone WHERE Date_Completed IS NULL ; | Clone_ID | Date_Received | Turnaround | | 3 | | 57 | | 4 | | 56 | | 6 | | 54 | rows in set (0.00 sec) Note CURRENT_DATE simply returns today’s date. You can also use this if you are entering data.

Lecture Who is waiting for clones? mysql> SELECT Scientist.Last_Name, COUNT(Clone.Clone_ID) AS Clones FROM Scientist, Clone WHERE Scientist.Scientist_ID = Clone.Requestor_ID AND Clone.Date_completed IS NULL GROUP BY Scientist.Last_name ; | Last_Name | Clones | | Hawkins | 2 | | Juriloff | 1 | rows in set (0.00 sec) Note we are now extracting data from multiple tables, therefore we need to be explicit in which fields are taken from each table. We do this through The table.field nomenclature. We “join” the tables through the fact that ID of the scientists is common between the tables. GROUP BY tells MySQL How to cluster the values after counting them.

Lecture Who has requested the most Clones mysql> SELECT Scientist.Last_Name, COUNT(Clone.Clone_ID) AS Clones FROM Scientist, Clone WHERE Scientist.Scientist_ID = Clone.Requestor_ID GROUP BY Scientist.Last_name ORDER BY Clones DESC ; | Last_Name | Clones | | Hawkins | 3 | | Carter | 2 | | Juriloff | 1 | rows in set (0.00 sec)

Lecture Easy Administration through myPHPadmin

Lecture Recommended Reading