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

Slides:



Advertisements
Similar presentations
CSE 1561 A Brief MySQL Primer Stephen Scott. CSE 1562 Introduction Once you’ve designed and implemented your database, you obviously want to add data.
Advertisements

CSE 190: Internet E-Commerce Lecture 10: Data Tier.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
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.
Oracle SQL*plus John Ortiz. Lecture 10SQL: Overview2 Overview  SQL: Structured Query Language, pronounced S. Q. L. or sequel.  A standard language for.
CSC 2720 Building Web Applications Database and SQL.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
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
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
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.
Information Systems Today (©2006 Prentice Hall) MySQL 1CS3754 Class Note #8, Is an open-source relational database management system 2.Is fast and.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CSC 2720 Building Web Applications Database and SQL.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
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.
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,
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
Databases and SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
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.
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
CS3220 Web and Internet Programming More SQL
CS320 Web and Internet Programming SQL and MySQL
Open Source Server Side Scripting Permissions & Users
Instructor: Jason Carter
Principles of Software Development
CS1222 Using Relational Databases and SQL
ISC440: Web Programming 2 Server-side Scripting PHP 3
CS1222 Using Relational Databases and SQL
Chengyu Sun California State University, Los Angeles
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
MySQL Database System Installation Overview SQL summary
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 forums Users, postings … anywhere where a large amount of information needs to be managed safely and efficiently

A Relational DB Example project_idemployee_id idfirst_namelast_nameaddresssupervisor_id 1JohnDoeStreet #215null 2JaneDoeStreet #7111 idnameleader_id 1Firestone1 2Blue2 projects project_members employees

Terminology DBMS DB Database Tables (relations) 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 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  /* */ ...

MySQL on the CS3 Server Version 5.5 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

Client-Server Architecture of MySQL ClientServer mysql MySQL Workbench phpMyAdmin Applications … Localhost CS3 … DB Server

Connect to a MySQL Database Use one of the client software Create a connection with the information about the server Host Port (default 3306) Username Password Database/Schema

Connect to Your MySQL Database on CS3 cysun/course_materials/cs3#MySQL Command line client mysql MySQL Workbench phpMyAdmin Change password set password = password (‘something');

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

Schema Design Example Employee and Project public class Employee { Integerid; StringfirstName; StringlastName; Stringaddress; Employeesupervisor; } public class Project{ Integerid; Stringname; Employeeleader; Set members; }

Simple Schema Design Rules OORelational ClassTable Class variablesAttributes Java typesSQL types Object ReferencesIDs CollectionNew Table (possibly)

Create a Table create table table_name ( field_name field_type [NOT NULL] [UNIQUE] [DEFAULT value], … [PRIMARY KEY(field_name, …)] ); create table employees ( id integer auto_increment primary key, first_name varchar(255) not null, last_name varchar(255) not null, address varchar(255), supervisor_id integer references employees(id) );

Naming Conventions Use plural form for table names Use singular form for column names Use underscore to concatenate multiple words, e.g. employee_id Do not use mixed cases in names (e.g. ArtistName ) because many DBMS treat names as case-insensitive

About CREATE TABLE Field types integer, real, char(n), varchar(n) date, time, datetime, timestamp auto_increment Integrity constraints unique, not null, primary key foreign key

Populate Tables insert into table values (value1, value2, …); insert into table (field, …) values (value, …);

Search for Records Find the name and address of employee with id=1 Find the name of employee who leads the project Firestone Find the name of Jane Doe’s supervisor Find the number of projects led by John Doe List the number of members of each project select field(s) from table(s) where condition(s);

Update Records Change John Doe’s address to 123 Main St. Change John Doe’s name to Tom Smith update table set field=value [, …] where condition(s);

Delete Records Delete all the projects led by John Doe Delete all the projects 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 projects; drop table if exists projects; -- MySQL only

Readings CS122 Textbook MySQL Reference Manual String functions Date and time functions