CS3220 Web and Internet Programming SQL and MySQL

Slides:



Advertisements
Similar presentations
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
Advertisements

ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
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.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
INTERNET APPLICATION DEVELOPMENT For More visit:
ASP.NET Programming with C# and SQL Server First Edition
 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.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Introduction to MySQL Lab no. 10 Advance Database Management System.
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.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Visual Programing SQL Overview Section 1.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
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.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
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.
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
Databases Stefano Grazioli.
Chengyu Sun California State University, Los Angeles
Web Systems & Technologies
CS 3630 Database Design and Implementation
CS3220 Web and Internet Programming More SQL
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
CS422 Principles of Database Systems Course Overview
Open Source Server Side Scripting Permissions & Users
Instructor: Jason Carter
Principles of Software Development
CS1222 Using Relational Databases and SQL
Database Management  .
ORACLE SQL Developer & SQLPLUS Statements
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
CS1222 Using Relational Databases and SQL
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
Intro to Relational Databases
CMPT 354: Database System I
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Chengyu Sun California State University, Los Angeles
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
A Very Brief Introduction to Relational Databases
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:

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

Web and Databases E-commerce sites News sites Web forums 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 employees id first_name last_name address supervisor_id 1 John Doe Street #215 null 2 Jane Street #711 projects project_members id name leader_id 1 Firestone 2 Blue project_id employee_id 1 2

Terminology DBMS DB DB DB Database Tables (relations) Views, indexes Procedures and triggers … Database

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 In MySQL, a database is sometimes also called a schema A database contains a number of database objects (a.k.a. schema elements) such as tables, indexes, stored procedures, and so on

More Terminology Table (relation) Attributes (fields, columns) student_id name 1001 John Doe 1002 Jane Doe Rows (Records) (Tuples) students Table (relation) schema: students( student_id, name ) 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.7 One database per account DB name is the same as the server account username. E.g. cs3220stu31 Username and password are the same as the ones for the server account

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

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 http://csns.calstatela.edu/wiki/content/cysun/course_materials/cs3#MySQL Command line client mysql MySQL Workbench phpMyAdmin Change password set password = password (‘something');

Run SQL Scripts Command line client MySQL Workbench phpMyAdmin \. 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 { Integer id; String firstName; String lastName; String address; Employee supervisor; } public class Project{ Integer id; String name; Employee leader; Set<Employee> members; }

Simple Schema Design Rules OO Relational Model Class Table Class variables Attributes Java types SQL types Object References IDs New Table (possibly) with reference back to the parent object Collection

Create a Table create table table_name ( field_name field_type [constraint(s)], … ); 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 auto_increment Integrity constraints integer, float, double, 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 select field(s) from table(s) where condition(s); Find the name and address of the employee with id=1 Find the name of the employee who leads the project Firestone

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

Delete Records delete from table where condition(s); Delete all the projects led by the employee with id = 1 Delete all the projects

Delete Tables drop table projects; drop table if exists projects;