CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.

Slides:



Advertisements
Similar presentations
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.
Advertisements

MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
Action Queries CS 320. Review: SQL Command Types  Data Definition Language (DDL)  Used to create and modify database objects  Data Manipulation Language.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
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.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
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.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
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.
INTERNET APPLICATION DEVELOPMENT For More visit:
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Lecture 9 – MYSQL and PHP (Part1) SFDV3011 – Advanced Web Development 1.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
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 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
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
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
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.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
>> 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 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
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.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
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.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Introduction to Database Programming with Python Gary Stewart
Web Systems & Technologies
CS320 Web and Internet Programming SQL and MySQL
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
Principles of Software Development
CS1222 Using Relational Databases and SQL
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS3220 Web and Internet Programming SQL and MySQL
Chapter 4 Introduction to MySQL.
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
CS4540 Special Topics in Web Development SQL and MS SQL
CS1222 Using Relational Databases and SQL
Presentation transcript:

CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles

Web and Databases E-commerce sites Products, order, customers News sites Subscribers, articles Web boards Users, postings … anywhere where a large amount of information needs to be managed safely and efficiently

Database vs. File SQL Faster search ACID Atomicity Consistency Isolation Durability

Relational Model Proposed by Edgar F. Codd in early 1970’s All major DBMS are relational (and the good ones are object-relational)

A Relational DB Example OIDCIDODATESDATE 114/29/2005NULL 223/20/20053/37/2005 OIDPIDQuantity CIDFNAMELNAMEADDRESS 1ChengyuSunStreet #215 2SteveSunStreet #711 PIDDescriptionPrice 1Intel P4$200 2Intel P3$49 3AthlonXP$100 4ASUS$128 5TYAN$400 orders products order_details customers

Terminology DBMS DB Database Schema Relations (tables) Views, indexes Procedures and triggers …

DBMS Database Management System (DBMS) is a software that manages databases Common DBMS Commercial – Oracle, IBM DB2, MS SQL Server, Access Open source – MySQL, PostgreSQL

Database and Schema A database is a collection of data managed by a DBMS A database contains one or more schemas A schema contains a number of schema elements, such as tables, indexes, stored procedures, and so on

More Terminology student_idname 1001John Doe 1002Jane Doe Attributes (fields, columns) Rows (Records) (Tuples) students Table (relation) schema: students( student_id, name ) Table (relation) Database schema: database name + table schemas

SQL Structured Query Language Standard query language of relational databases Supported by all major relational databases with some variations

SQL Script A text file contains SQL statements and comments Statements: select, insert, create … Comments  lines started with --  MySQL also supports C-style comment syntax, i.e. /* */ Usually uses the.sql suffix

MySQL Very popular in web development Open source Very fast search Full text indexing and search Developer-friendly features  drop table if exists  insert... on duplicate key update  /* */ ...

Databases in MySQL MySQL Server tables indexes constraints views... database user information access privileges mysql In MySQL, schema = database

MySQL on the CS3 Server Version One database per account DB name is the same as the server account username. E.g. cs320stu31 Username and password are the same as the ones for the server account

Connect to a MySQL Database Host Port (default 3306) Database Username Password

Connect to Your MySQL Database on CS3 eaching/servers/cs3.html#MySQL Command line client mysql MySQL Query Browser phpMyAdmin Change password set password = password (‘something');

Run SQL Scripts Command line client \. path/to/script.sql source path/to/script.sql; MySQL Query Browser File  Open Script..., then Execute phpMyAdmin Import  Format of the imported file: SQL

Create a Table create table table_name ( field_name field_type [NOT NULL] [UNIQUE] [DEFAULT value], … [PRIMARY KEY(field_name, …)] ); create table products ( prod_id char(8) not null,-- product id description text,-- product description price decimal(12,2),-- price primary key (prod_id) );

Field Types Numerical types int, float, double, decimal(m,n) String types char(n), varchar(n) Date and time date, time, datetime, timestamp  ‘YYYY-MM-DD hh:mm:ss’

Auto Increment Field create table users ( idint auto_increment primary key, usernamevarchar(64) not null unique, passwordchar(16) ); insert into users (username,password) values (‘cysun’,’abcd’); insert into users (username,password) values (‘csun’,’xyz’);

Populate Tables insert into orders values (1000, 1, ‘ ’, ‘ ’); insert into orders (oid, cid, odate) values (1001, 2, ‘ ’); insert into table values (value1, value2, …); insert into table (field, …) values (value, …);

Search for Records select description, price from products; select * from products; select * from products where price < 300; select * from products where prod_id = ‘cpu-0001’; select field(s) from table(s) where condition(s);

Pattern Matching LIKE, REGEXP % -- any zero or more characters. – any single charater [abc], [a-z], [0-9] – range * -- zero or more instances of the preceding character ^ -- beginning of a string $ -- end of a string select * from products where description like ‘%intel%’;

Update Records update table set field=value [, …] where condition(s); update products set price=320 where prod_id = ‘cpu-0001’; update products set price=200, description=‘Intel Pentium M 1.7GHz’ where prod_id = ‘cpu-0001’;

Delete Records delete from orders; delete from orders where odate < ‘ ’ and sdate is not null; delete from table where condition(s);

Delete Tables and Databases Delete a database drop database cs320stu31; -- don’t do this! Delete a table drop table products; drop table if exists products; -- MySQL only

Schema Design Example … Customer, Product, Order public class Customer { intid; StringlastName; StringfirstName; Stringaddress; } public class Product { intid; Stringdescription; doubleprice; }

… Schema Design Example public class Order { intid; DatedateOrdered; DatedateShipped; Customercustomer; Map products; }

Simple Schema Design Rules OORelational ClassTable Class variablesAttributes Java typesSQL types ReferencesID CollectionNew Table

Exercises Read MySQL Reference Manual String functions Date and time functions