Working with MySQL A290/A590, Fall 2014 10/07/2014.

Slides:



Advertisements
Similar presentations
MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
Advertisements

CSE 190: Internet E-Commerce Lecture 10: Data Tier.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Databases Dan Otero Alex Loddengaard
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
1 CSE 480: Database Systems Lecture 9: SQL-DDL Reference: Read Chapter of the textbook.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Database Systems Marcus Kaiser School of Computing Science Newcastle University.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
Information Systems Today (©2006 Prentice Hall) MySQL 1CS3754 Class Note #8, Is an open-source relational database management system 2.Is fast and.
Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
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.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Introduction to MySQL Lab no. 10 Advance Database Management System.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
CSC 2720 Building Web Applications Database and SQL.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
M1G Introduction to Database Development 2. Creating a Database.
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.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
CS499 Project #3 XML mySQL Test Generation Members Erica Wade Kevin Hardison Sameer Patwa Yi Lu.
Database revision.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Visual Programing SQL Overview Section 1.
SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
>> 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.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
SQL. What is a database? G a collection of data G Usually consists of entities and relations G An entity is an individual “object” that exists and is.
Relational Database Design and MySQL Charles Severance
Chapter 3: Relational Databases
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.
Introduction to Database Programming with Python Gary Stewart
Lecture 1.21 SQL Introduction Steven Jones, Genome Sciences Centre.
Big Data Yuan Xue CS 292 Special topics on.
Fundamentals of DBMS Notes-1.
CS320 Web and Internet Programming SQL and MySQL
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
Referential Integrity MySQL
Principles of Software Development
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Session - 6 Sequence - 1 SQL: The Structured Query Language:
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
Data Definition Language
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
Presentation transcript:

Working with MySQL A290/A590, Fall /07/2014

The MySQL Server A MySQL server can be given SQL commands, executes them, and returns the results to the connected application – Like Apache, we need to assign a port number on the system to MySQL on which it will listen for requests Starting the server Stopping the server

Command Line Interface Starting the MySQL client Commands for looking around in the database –SHOW DATABASES –USE database –SHOW TABLES –DESCRIBE table

Databases Advantages – concurrency – fast access to the data that is transparent to the db user – uses tables, a general data structure that can implement any data model – unified language for accessing and manipulating the data in the database (SQL) Disadvantages – For certain tasks, can be an overkill as far as complexity and storage requirements are concerned

Database Tables A typical database table definition has: – a name – a list of columns and their data types – a list of constraints primary key to ensure uniqueness (if necessary) foreign keys to facilitate relationships w/ other tables indices to facilitate fast look ups

Database Structure For Quizes iddescriptioncreation_date 1Favorite Things Quiz 10/07/ :22 idtextquiz_id 1What is your favorite color? 1 2What is your favorite book? 1 … idtextpoint_valuequestion_id 1Red11 2Green101 … quiz table question table answer table

Data Relationships One-To-Many: the relationship between the quiz and question tables, or question and answer tables – One quiz can have many questions, but a question can only have one associated quiz – One question can have many possible answers, but an answer can have only one associated question

Keeping Track of Users and Their Quizes id password ndiana.edu … iddescriptioncreation_date 1Favorite Things Quiz 10/07/ :22 AM quiz table user table user_idquiz_idscoredate_taken /07/ :00 AM … user_scores table

Table Relationships Many-To-Many: the relationship defined in the user_scores table – One quiz can be taken by many users – One user can take many quizes

Creating The Database Schema CREATE TABLE quiz ( id INT NOT NULL AUTO_INCREMENT, description VARCHAR(255), create_time DATETIME NOT NULL, PRIMARY KEY(id) ) CREATE TABLE question ( id INT NOT NULL AUTO_INCREMENT, text VARCHAR(255), quiz_id INT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (quiz_id) REFERENCES quiz(id) ON DELETE CASCADE ) CREATE TABLE answer ( id INT NOT NULL AUTO_INCREMENT, text VARCHAR(255) NOT NULL, point_value INT NOT NULL, question_id INT NOT NULL, PRIMARY KEY(id), FOREIGN KEY question_id REFERENCES question(id) ON DELETE CASCADE )

Creating the Database Schema CREATE TABLE user ( id INT NOT NULL AUTO_INCREMENT, VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL PRIMARY KEY (id) ) CREATE TABLE user_scores ( user_id INT NOT NULL, quiz_id INT NOT NULL, score INT NOT NULL, date_taken DATETIME NOT NULL, PRIMARY KEY (user_id, quiz_id), FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE, FOREIGN KEY (quiz_id) REFERENCES quiz(id) ON DELETE CASCADE )

Filling In the Details Data types: – Numbers: INT, LONGINT, NUMERIC, FLOAT, DOUBLE – Strings: VARCHAR( >), TEXT, BLOB – Other: DATETIME NOT NULL vs NULL: whether to allow empty values or not PRIMARY KEY and FOREIGN KEY CASCADE: Keeping the data clean and robust

Viewing and Manipulating Data in MySQL SELECT – SELECT * FROM quiz; – SELECT a.text, a.point_value FROM answer a – SELECT a.text FROM answer a WHERE a.point_value > 2 INSERT – INSERT INTO quiz VALUES (NULL, 'Test Quiz', NOW()) DELETE – DELETE FROM answer WHERE point_value >= 3 UPDATE – UPDATE quiz SET description = 'Test' WHERE id=1

Viewing Data From Multiple Tables How do we view all questions and their answers for a particular quiz iddescriptioncreation_dat e 1Favorite Things Quiz 10/07/ :22 idtextquiz_id 1What is your favorite color? 1 2What is your favorite book? 1 … idtextpoint_valuequestion_id 1Red11 2Green101 …

Using INNER JOIN SELECT quiz.description, q.text, a.text, a.point_value FROM quiz q INNER JOIN question qn ON q.id =qn.quiz_id INNER JOIN answer a ON qn.id=a.question_id

Interface Between Python and MySQL See examples.