MySql In Action Step by step method to create your own database.

Slides:



Advertisements
Similar presentations
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Advertisements

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.
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
Creating a Blank Database 1. Open up Microsoft Access 2. Click on Blank document button 3. On the right panel, Specify the location for saving your database.
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”
Intermediate PHP & MySQL
Introduction to Structured Query Language (SQL)
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
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.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
SQL Query Extras MIS 433. Rerunning the last Query n Type the forward slash “/” to rerun the last query that was entered.
SQL | PHP Tutorial at 8am. god, it’s early.. SQL intro There are many different versions of SQL available for usage. Oracle MySQL SQLite DB2 Mimer The.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
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:
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Creating Databases with MySQL Workbench Build the Forums database in Ullman’s Chapter 6.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Python MySQL Database Access
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
CSC 2720 Building Web Applications Database and SQL.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
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.
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.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
1 COP 4710 Databases Fall, 2000 Today’s Topic Chapter 7: SQL David A. Gaitros October 9th, 2000 Department of Computer Science.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 7: SQL, the Structured Query Language Instructor’s name and.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
SQL ACTION QUERIES AND TRANSACTION CONTROL CS 260 Database Systems.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database /
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 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.
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Database application MySQL Database and PhpMyAdmin
ISC440: Web Programming 2 Server-side Scripting PHP 3
PHP and MySQL.
CS3220 Web and Internet Programming SQL and MySQL
Projecting output in MySql
Day 2 - Basic Database Backbone
CS122 Using Relational Databases and SQL
MySQL Database System Installation Overview SQL summary
SQL Basics BCHB697.
CS1222 Using Relational Databases and SQL
CS3220 Web and Internet Programming SQL and MySQL
SQL AUTO INCREMENT Field
Presentation transcript:

MySql In Action Step by step method to create your own database

CSE 498MySql In Action2/44 What is next? Having convinced that MySql is a strong tool to develop databases, you are wondering if you can use it to develop your own business. Having convinced that MySql is a strong tool to develop databases, you are wondering if you can use it to develop your own business. This is the story. This is the story. –You want to open a small video rental in Seattle. You are thinking to create a small database to keep track what kind of films that you have, how long the films are checked out, and how much money that a customer has to pay for renting a film. –Since you already know that MySql is easy to use, you will use it for developing your own database.

CSE 498MySql In Action3/44 Database Structure for Video Rental I After spending some time, you come up with the following structure of the database that you need for your small video rental. After spending some time, you come up with the following structure of the database that you need for your small video rental. –Customers customerID ( int ) => Primary KeycustomerID ( int ) => Primary Key firstName ( VarChar(20) )firstName ( VarChar(20) ) lastName ( VarChar(20) )lastName ( VarChar(20) ) address ( VarChar(20) )address ( VarChar(20) ) –Rentals movieID ( int ) => Primary KeymovieID ( int ) => Primary Key title ( VarChar(20) )title ( VarChar(20) ) copyNum ( int )copyNum ( int )

CSE 498MySql In Action4/44 Database Structure for Video Rental II –CheckOut entryID ( int ) => Primary KeyentryID ( int ) => Primary Key customerID ( int )customerID ( int ) movieID ( int )movieID ( int ) checkOutDate ( date/time )checkOutDate ( date/time ) duration ( int )duration ( int ) cost ( double )cost ( double )

CSE 498MySql In Action5/44 Connecting To MySql Until this point, you are ready to create tables to implement your database. Until this point, you are ready to create tables to implement your database. The first step that you have to do is to connect to MySql by using your favorite tool, such as Telnet or x-window. The first step that you have to do is to connect to MySql by using your favorite tool, such as Telnet or x-window. I assume that you already contacted the database administrator to create a blank database which is called “video_rental”. I assume that you already contacted the database administrator to create a blank database which is called “video_rental”. On the prompt, type in mysql -p video_rental On the prompt, type in mysql -p video_rental –‘-p’ option is used to tell MySql that you will use password to connect to your database.

CSE 498MySql In Action6/44 Connecting To MySql (Cont….) After you logon to MySql, you should get similar result as the following: After you logon to MySql, you should get similar result as the following: Note: Note: –I use x-window to logon to MySql –On the prompt, it displays cochise is the name of the server that I use, andcochise is the name of the server that I use, and ffaizal is my login name in that server.ffaizal is my login name in that server. –You should get similar prompt when you logon to MySql.

CSE 498MySql In Action7/44 Creating Customers table The next step is to create tables on the video_rental database. The next step is to create tables on the video_rental database. The First table that you will create is Customers table. The First table that you will create is Customers table. To create that table, you need to use create table command. To create that table, you need to use create table command. In this case, you should use In this case, you should use create table Customers (customerID int unsigned auto_increment primary key, firstName varchar(20) not null default ‘N/A’, lastName varchar(20) not null default ‘N/A’, address varchar(30) not null default ‘N/A’); create table Customers (customerID int unsigned auto_increment primary key, firstName varchar(20) not null default ‘N/A’, lastName varchar(20) not null default ‘N/A’, address varchar(30) not null default ‘N/A’);

CSE 498MySql In Action8/44 Creating Customers table (Cont….) If you want to know and check the table that you just created, you can use show command. If you want to know and check the table that you just created, you can use show command. –I used show columns from Customers;

CSE 498MySql In Action9/44 Creating Customers table (Cont….) Note: Note: –customerID is a primary key. I declared it as an unsigned integer with auto increment so that I can always get the unique number. –For the rest of the table, I declared them as variable characters with a default value N/A. –In all columns, I will not allow them to have null as value.

CSE 498MySql In Action10/44 Creating Rentals table The second table that you should create is Rentals table. The second table that you should create is Rentals table. Following the syntax from the previous table creation, you should come up with the following command: Following the syntax from the previous table creation, you should come up with the following command: create table Rentals (movieID int unsigned auto_increment primary key, title varchar(20) not null default ‘N/A’, copyNum int unsigned not null); create table Rentals (movieID int unsigned auto_increment primary key, title varchar(20) not null default ‘N/A’, copyNum int unsigned not null);

CSE 498MySql In Action11/44 Creating Rentals table (Cont….) Note: Note: –movieID is a primary key. I declared it as an auto-incremented unsigned integer. –Title is a variable character with default value ‘N/A’. –copyNum is an integer with 0 as its default value.

CSE 498MySql In Action12/44 Creating CheckOut table CheckOut table is the last table that you need to create. CheckOut table is the last table that you need to create. Following the syntax from the previous slides, the command will be as the following: Following the syntax from the previous slides, the command will be as the following: create table CheckOut(entryID int unsigned auto_increment primary key, customerID int unsigned not null, movieID int unsigned not null, checkOutDate datetime not null default 'N/A', duration int unsigned not null, cost double unsigned not null); create table CheckOut(entryID int unsigned auto_increment primary key, customerID int unsigned not null, movieID int unsigned not null, checkOutDate datetime not null default 'N/A', duration int unsigned not null, cost double unsigned not null); If you succeeded in creating the table, you will get the same result as the one shown on the next page. If you succeeded in creating the table, you will get the same result as the one shown on the next page.

CSE 498MySql In Action13/44 Creating CheckOut table (Cont….) Note: Note: –entryID is used as a primary key, instead of customerID and movieID. MySql does not allow more than two primary keys on the same table. –The rest of the table should be clear from the above screenshot.

CSE 498MySql In Action14/44 Checking Your Database The quick way to check all tables that you have created is by using the show tables command. The quick way to check all tables that you have created is by using the show tables command. Congratulation…. You have successfully created three tables in the video_rental database. Congratulation…. You have successfully created three tables in the video_rental database.

CSE 498MySql In Action15/44 Inserting data into the tables After you have created tables in video_rental database, it’s time for you to input the data. After you have created tables in video_rental database, it’s time for you to input the data. Suppose that you have invested some money to buy five copies of “StarWars” and you want to store this information into your Rentals table. Suppose that you have invested some money to buy five copies of “StarWars” and you want to store this information into your Rentals table. How do you do that??? How do you do that???

CSE 498MySql In Action16/44 Inserting data into the tables (Cont.) Use insert command. Use insert command. The command should look like the following: The command should look like the following: –insert into Rentals (title, copyNum) values ('StarWars', 5); Since the movieID is auto-increment integer, I do not have to explicitly give a value. It is done automatically for you. Since the movieID is auto-increment integer, I do not have to explicitly give a value. It is done automatically for you. If the insertion is successful, you will have the similar result as the one on the next slide. If the insertion is successful, you will have the similar result as the one on the next slide.

CSE 498MySql In Action17/44 Inserting data into the tables (Cont.) To see the entry in the table, you can use “select * from Rentals;”. To see the entry in the table, you can use “select * from Rentals;”. –* means that you want to see all available columns in the table Remember to use ‘ or “ at the beginning and at the end of the string values. Remember to use ‘ or “ at the beginning and at the end of the string values.

CSE 498MySql In Action18/44 All entries are already inserted Congratulation…. Congratulation…. To shorten your time, all the data insertions are already done for you. To shorten your time, all the data insertions are already done for you. Customers table

CSE 498MySql In Action19/44 All entries are already inserted (Cont.) Rentals table CheckOut table

CSE 498MySql In Action20/44 Deleting data from a table You can delete an entry from a table by using delete command. You can delete an entry from a table by using delete command. Suppose that you inserted a wrong data in CheckOut table as shown at the last row of the following table. Suppose that you inserted a wrong data in CheckOut table as shown at the last row of the following table. –There is no customer with ID# 4 and there is not movie with ID# 4 as well.

CSE 498MySql In Action21/44 Deleting data from a table (Cont.) I used the following query to delete the last row: I used the following query to delete the last row: –delete from CheckOut where entryID = 4; –You can use different condition on where clause, such as customerID = 4.

CSE 498MySql In Action22/44 Deleting a table from a database In addition to record deletion command, MySql also provides a command to delete a table from a database. In addition to record deletion command, MySql also provides a command to delete a table from a database. Use drop table command to delete a table. Use drop table command to delete a table. Suppose that you want to delete a table whose name is service, you can use the following command: Suppose that you want to delete a table whose name is service, you can use the following command: –drop table service;

CSE 498MySql In Action23/44 Deleting more than one table You can also use the drop table command to delete more than one table at the same time by cascading the table names. You can also use the drop table command to delete more than one table at the same time by cascading the table names. Suppose that in addition to service, you also want to delete tables pay and time. You can delete them by using: Suppose that in addition to service, you also want to delete tables pay and time. You can delete them by using: –drop table service, pay, time;

CSE 498MySql In Action24/44 Select-Form-Where query Like almost all SQL query, MySql uses Select, From, and Where syntax to retrieve some information form the database. Like almost all SQL query, MySql uses Select, From, and Where syntax to retrieve some information form the database. The Form clause is usually used to indicate which relation(s) to which the query refers. The Form clause is usually used to indicate which relation(s) to which the query refers. The Where clause is consist of the condition in which tuples must satisfy. The Where clause is consist of the condition in which tuples must satisfy. The Select clause is consist of attribute(s) of tuples that match the condition(s). The Select clause is consist of attribute(s) of tuples that match the condition(s).

CSE 498MySql In Action25/44 Select-Form-Where query (Cont.) Suppose that you want to retrieve the information about your customer whose last name is Doe. Suppose that you want to retrieve the information about your customer whose last name is Doe. The proper query will be The proper query will be select * from Customers where lastName = ‘Doe’; Note: * means that you want to retrieve all information about the customer whose last name is Doe.

CSE 498MySql In Action26/44 Select-Form-Where query (Cont.) The result of the query is shown below. The result of the query is shown below.