Introduction to MySQL Lab no. 9 Advance Database Management System.

Slides:



Advertisements
Similar presentations
Session 2Introduction to Database Technology Data Types and Table Creation.
Advertisements

VTYS 2012 Mehmet Emin KORKUSUZ Ders  Create  Alter  Drop Data Defination Language.
Database Chapters.
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Pertemuan ke 2 Tipe data & ERD Kurniawan Eka Permana.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
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.
MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
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.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
1 CSE 480: Database Systems Lecture 9: SQL-DDL Reference: Read Chapter of the textbook.
Oracle Data Definition Language (DDL)
Copyright © Curt Hill SQL The Data Definition Language.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Basis Data Terapan Yoannita. SQL Server Data Types Character strings: Data typeDescriptionStorage char(n)Fixed-length character string. Maximum 8,000.
ASP.NET Programming with C# and SQL Server First Edition
Information Systems Today (©2006 Prentice Hall) MySQL 1CS3754 Class Note #8, Is an open-source relational database management system 2.Is fast and.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
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.
CSC 2720 Building Web Applications Database and SQL.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
Advanced Database Management System
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.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
MySQL More… 1. More on SQL In MySQL, the Information Schema is the “Catalog” in the SQL standard SQL has three components: Data definition Data manipulation.
Advanced Web 2012 Lecture 3 Sean Costain What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Sql DDL queries CS 260 Database Systems.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
LECTURE FOUR Introduction to SQL DDL with tables DML with tables.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.
Lecture 1.21 SQL Introduction Steven Jones, Genome Sciences Centre.
Database commands : DDL
3 A Guide to MySQL.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
MYSQL INTERVIEW QUESTIONS AND ANSWERS
Database systems Lecture 2 – Data Types
CIS 136 Building Mobile Apps
MySQL Database System Installation Overview SQL summary
Kirkwood Center for Continuing Education
Database Instructor: Bei Kang.
SQL (Structured Query Language)
Presentation transcript:

Introduction to MySQL Lab no. 9 Advance Database Management System

Lab Outline MySQL PHP

What is MySQL? MySQL is the most popular open-source (relational) database system.

MySQL MySQL can be scaled down to support embedded database applications. Perhaps because of this reputation many people believe that MySQL can only handle small to medium-sized systems. The truth is that MySQL is the de-facto standard database for web sites that support huge volumes of both data and end users (like Friendster, Yahoo, Google).

Starting MySQL Console Left click WAMP server icon on task bar Click MySQL Click MySQL console

MySQL Console The console will ask for password. Press Enter key You will see mysql prompt You can now start typing commands… Try the following: mysql> show databases;

Create a Database The CREATE DATABASE statement is used to create a database in MySQL. Syntax CREATE DATABASE database_name Example mysql> CREATE DATABASE guestbook;

Creating a Table Syntax CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type,.... ) ; Example mysql>CREATE TABLE profile ( ID int, Name varchar(30) ); Note: you must specify database on prompt before creating a table mysql> use database_name;

Column Data Types String types – Char – Varchar – tinytext/tinyblob – text/blob – mediumtext/mediumblob – longtext/longblob – enum – set

Column Data Types Numeric types – int/integer – tinyint – mediumint – bigint – float – double/double precision/real – decimal/numeric

Column Data Types Date Time Data Types – date – datetime – timestamp – time – year

Column Characteristics Unique – when this parameter is turned on, MySQL makes sure that absolutely no duplicates exist for a particular field. – it can be used with any field Auto Increment – automatically increases column value by one whenever a new record is added. – You don’t have to worry about what the last ID number was; the field automatically keeps track for you. null/not null – whether or not the field can be empty – If a field has been defined as not null and nothing is entered by the user, MySQL will enter a “0” in the field instead of producing an error

Example CREATE TABLE grocery_inventory ( id int not null primary key auto_increment, item_name varchar (50) not null, item_desc text, item_price float not null, curr_qty int not null ) ;

Detailed Description of Data Types

char Usage: char (length) Description: – Max length supported 255 characters – Fixed Length Type (Spaces are padded from the right). Spaces are removed on data retrieval. – Defining a length is not required. Default is 1. – Automatic Truncation for more than 255 Characters

VarChar Usage : varchar(length ) Description : – Max length supported 255 characters – Varible Length Type (Value is adjusted as per value) – Automatic Truncation for more than 255 Characters Note: If you define a column as varchar with a column length of less than four, MySQL will automatically change the column to the char type. Similarly, if you try to mix chars and varchars with a column length of more than four, they all become varchars.

Text / Blob Usage: text/blob – maximum length of characters. – BLOBs are "Binary Large Objects" and are used to store large amounts of binary data, such as images or other types of files. – Fields defined as TEXT also hold large amounts of data; the difference between the two is that sorts and comparisons on stored data are case sensitive on BLOBs and are not case sensitive in TEXT fields. – You do not specify a length with BLOB or TEXT.

Tiny Medium and Long text /blob TINYBLOB or TINYTEXT – A BLOB or TEXT column with a maximum length of 255 characters. You do not specify a length with TINYBLOB or TINYTEXT. MEDIUMBLOB or MEDIUMTEXT – A BLOB or TEXT column with a maximum length of characters. You do not specify a length with MEDIUMBLOB or MEDIUMTEXT. LONGBLOB or LONGTEXT – A BLOB or TEXT column with a maximum length of characters. You do not specify a length with LONGBLOB or LONGTEXT.

enum - An enumeration is a fancy term for "list." - When defining an ENUM, you are creating a list of items from which the value must be selected (or it can be NULL). -For example, if you wanted your field to contain either "A" or "B" or "C", you would define your ENUM as ENUM ('A', 'B', 'C') and only those values (or NULL) could ever populate that field. -ENUMs can have different values. -Example : create table my_table ( id int auto_increment primary key, answer enum (‘yes’, ‘no’) default ‘no’ );

set Syntax: set (‘value1’, ‘value2’, ‘value3’ ?) [default ‘value’] This column type defines a superset of values. It allows for zero or more values from the list you specify to be included in a field.

Numeric Types int/integer tinyint mediumint bigint float double/double precision/real decimal/numeric

Int/integer Syntax: int(display size) [unsigned] [zerofill] – With unsigned flag, 0 to 4,294,967,295. – With signed flag, 2,147,483,648 to 2,147,483,647. – int will often be used with auto_increment to define the primary key of a table. Usage: create table my_table ( table_id int unsigned auto_increment primary key, next_column text );

tinyint Syntax: tinyint(display size) [unsigned] [zerofill] – If unsigned, tinyint stores integers between 0 and 255. – If signed, the range is from -128 to 127. – Zerofill is optional like unsigned. Usage: create table my_table2 ( table_id tinyint(150) unsigned zerofill, next_column text );

mediumint Syntax: mediumint(display size) [unsigned] [zerofill] – With unsigned flag, mediumint stores integers between - 8,388,608 and 8,388,607. – With signed flag, the range is from 0 to Usage: create table my_table2 ( table_id mediumint(150) unsigned zerofill, next_column text );

Float Float has two distinct usages. Syntax: float(precision) [zerofill] – In this usage, float stores a floating-point number and cannot be unsigned. – The precision attribute can be ≤ 24 for a single-precision floating-point number, and between 25 and 53 for a double-precision floating-point number. Syntax: float[(M,D)] [zerofill] – This is a small (single-precision) floating-point number and cannot be – unsigned. Allowable values are E+38 to E-38, zero, and E-38 to E+38. – M is the display width and D is the number of decimals. If the float attribute is used without an argument or with an argument of ≤ 24, the column will store a single-precision floating-point number.

double/double precision/real Syntax: double[(M,D)] [zerofill] – This column stores a double-precision floating-point number and cannot be unsigned. – Allowable values are – E+308 to E-308, zero, and E- 308 to E+308. – M is the display width and D is the number of decimals.

decimal Syntax: decimal[(M[,D])] [zerofill] Numbers in a decimal column are stored as characters. Each number is stored as a string, with one character for each digit of the value. M is the display width, and D is the number of decimals. If M is left out, it’s set to 10. If D is 0, values will have no decimal point. The maximum range of decimal values is the same as for double. Remember, though, that decimal, like all real types, can cause rounding errors.

Date Time Data Type date datetime timestamp time year

Example & sample usage create table date_test( id int unsigned auto_increment primary key, a_date date ); The following insert statements are all interpreted correctly by MySQL: – insert into date_test (a_date) values (‘ ’); – insert into date_test (a_date) values (‘ ’); – insert into date_test (a_date) values (‘ ’); – insert into test6 (a_date) values (000601);

Usage of Date Time date – Usage: date – The date column type stores values in the format YYYY-MM-DD. It will allow values between and datetime – Usage: datetime [null | not null] [default] – The datetime type stores values in the format YYYY-MM-DD HH:MM:SS. It will allow values between :00:00 and :59:59. timestamp – Usage: timestamp(size) – This is a handy column type that will automatically record the time of the most recent change to a row, whether from an insert or an update. Size can be defined as any number between 2 and 14.

Timestamp formats

Use this command to view all tables in your database: mysql> show tables;

Insert Command A statement with all columns named : insert into grocery_inventory (id, item_name, item_desc, item_price, curr_qty) values ('1', 'Apples', 'Beautiful, ripe apples.', '0.25', 1000); A statement that uses all columns but does not explicitly name them: insert into grocery_inventory values ('2', 'Bunches of Grapes', 'Seedless grapes.', '2.99', 500); Read Sams e-book to understand auto increment fields

Select Command Syntax: SELECT expressions_and_columns FROM table_name [WHERE some_condition_is_true] [ORDER BY some_column [ASC | DESC]] [LIMIT offset, rows] Example: select * from grocery_inventory; LIMIT clause is used to return only a certain number of records in your SELECT query result. The offset is the starting position of row

MySQL Tables Two types of tables: – transaction-safe tables (TSTs) – non-transaction-safe tables (NTSTs). TSTs – Transaction-safe tables allow lost data to be recovered, or a rollback of data to revert changes recently made. NTSTs – Non-transaction-safe tables are much faster and require much less memory to process updates – changes are permanent

MySQL Storage Engines Current version of MySQL uses five main types of storage engines to store and update data in these tables (TST, NTST): – MyISAM – MERGE – MEMORY (formerly known as HEAP) – InnoDB – BDB

Storage Engines (contd..) MyISAM – default storage engine – Usually sufficient for the average user’s needs. – supports all the field types, parameters, and functions. – supports NTSTs – replaces the ISAM storage engine from long ago.

Storage Engines (contd..) MERGE – can manipulate several identical MyISAM tables as one entity. – supports NTSTs.

Storage Engines (contd..) MEMORY – mostly used for temporary tables because of their incredible speed – they don’t support a lot of the common features of the MyISAM table, such as auto_increment and blob/text columns. – This type should be used in unique circumstances only. for example, when working with user logs, if you wanted to store the information in a temporary table. – supports NTSTs.

Storage Engines (contd..) InnoDB – This type, along with the BDB type, supports TSTs. – meant for extremely large and frequently accessed applications. – “row-locking” mechanism to prevent different users from attempting to change or add the same row to the table. – According to the source Web site, one instance of this type of table has been shown to support 800 inserts and updates per second! – You can also read more about this type at its – own Web site:

Storage Engines (contd..) BDB – BDB, or BerkeleyDB, is the other type of table that supports TSTs. – It is actually its own entity that works closely with the MySQL server and can be downloaded from – Like InnoDB tables, it is meant to support very large applications with literally thousands of users attempting to insert and update the same data at the same time. – There is a complete reference manual available at its source Web site.

mysql> SHOW ENGINES\G *************************** 1. row *************************** Engine: MyISAM Support: DEFAULT Comment: Default engine as of MySQL 3.23 with great performance *************************** 2. row *************************** Engine: MEMORY Support: YES Comment: Hash based, stored in memory, useful for temporary tables *************************** 3. row *************************** Engine: InnoDB Support: YES Comment: Supports transactions, row-level locking, and foreign keys *************************** 4. row *************************** Engine: BerkeleyDB Support: NO Comment: Supports transactions and page- level locking *************************** 5. row *************************** Engine: BLACKHOLE Support: YES Comment: /dev/null storage engine (anything you write to it disappears)...

Introduction to phpMyAdmin Left click on WAMP server icon and select phpMyAdmin Your action will open phpMyAdmin in your browser window

phpMyAdmin While exploring this GUI based utility, we will learn how to – Create a database – Create/design tables – Set table column/field characteristics – Modify existing table design options – Insert, select, update, delete data rows – Dropping tables and databases