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.

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

Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
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.
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.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
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.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
IE 423 – Design of Decision Support Systems Database development – Relationships and Queries Introduction to SQL.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Copyright © Curt Hill Index Creation SQL.
Information Systems Today (©2006 Prentice Hall) MySQL 1CS3754 Class Note #8, Is an open-source relational database management system 2.Is fast and.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
SQL (DDL & DML Commands)
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Advanced Database Management System
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.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
CN2180 MS SQL Server Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP.
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.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
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.
 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.
3 A Guide to MySQL.
Chapter 5 Introduction to SQL.
SQL: Schema Definition and Constraints Chapter 6 week 6
Insert, Update and the rest…
SQL Creating and Managing Tables
ISC440: Web Programming 2 Server-side Scripting PHP 3
SQL Creating and Managing Tables
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
SQL Creating and Managing Tables
IST 318 Database Administration
Instructor: Samia arshad
Presentation transcript:

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 code that makes up MySQL, is freely available to anyone. People all over the world can add to MySQL, fix bugs, make improvements, or suggest optimizations. It's grown so quickly because of the countless dedicated people who have contributed to the project in some way, as well as the dedication of the MySQL team. MySQL is faster, more reliable, and cheaper—or, simply put, better—than any other database system (including commercial systems such as Oracle and DB2)

Case Sensitivity SQL keywords are not case sensitive. This is standard across database systems. In MySQL, whether database and table names are case sensitive depends on your operating system. If you are using Windows, database and table names are not case sensitive, but if you are using a Unix-like operating system, they are. it is good practice to treat all identifiers as case sensitive, even if you are working on a Windows system Column names, indexes, and aliases are never case sensitive in MySQL.

MySQL Data Types MySQL uses many different data types, which are broken into three categories: numeric, date and time, and string types. 1.) Numeric Data Types

MySQL Data Types 2.) Date and Time Types

MySQL Data Types 2.) String Types

Options and Attributes A variety of options and additional attributes can be specified when a column is created.

Managing Databases and Tables 1.) Logging on to MYSQL Fire up the mysql client by issuing the following command at your command prompt: > mysql –u USER –p PASSWORD For example, if your database username and password are "phpuser" and "phppass“. The command would look like this: >mysql –u phpuser –p >enter password:phppass 2.) Creating database The CREATE DATABASE statement can create a new, empty database without any tables or data. The following statement creates a database called employee: mysql> CREATE DATABASE employee; 3.) Selecting Databases The USE statement selects a database to make it the default (current) database for a given connection to the server: USE db_name; Example : mysql> use employee;

Managing Databases and Tables 4.) Dropping Databases Dropping a database is just as easy as creating one, assuming that you have sufficient privileges: DROP DATABASE db_name; Example : mysql> DROP DATABASE employee; 5.) Creating Tables To create the tables in the employee database, we use the CREATE TABLE SQL statement. The usual form of this statement is: create table tablename ( table definition ) [ENGINE=table_type]; create table department( departmentID int not null auto_increment primary key, name varchar(20) )ENGINE=InnoDB;

Managing Databases and Tables create table employee( employeeID int not null auto_increment primary key, name varchar(80), job varchar(15), departmentID int not null, Foreign key (departmentID) references department(departmentID) ) ENGINE=InnoDB; 6.) Dropping Tables Dropping a table is much easier than creating it because you don't have to specify anything about its contents. You just have to name it: DROP TABLE tbl_name; You can drop several tables by specifying them all on the same statement: DROP TABLE tbl_name1, tbl_name2,... ; example: mysql> drop table employee;

Managing Databases and Tables 7.) Altering Table Structure You can also use ALTER TABLE to rename tables, add or drop columns, change column data types, A.) Changing a column's data type To change a data type, you can use either a CHANGE or MODIFY clause. Example: ALTER TABLE mytbl MODIFY i MEDIUMINT UNSIGNED; ALTER TABLE mytbl CHANGE i i MEDIUMINT UNSIGNED; Why is the column named twice in the command that uses CHANGE? Because one thing that CHANGE can do that MODIFY cannot is to rename the column in addition to changing the type. If you had wanted to rename i to j at the same time you changed the type, you'd do so like this: ALTER TABLE mytbl CHANGE i j MEDIUMINT UNSIGNED;

Managing Databases and Tables 7.) Altering Table Structure You can also use ALTER TABLE to rename tables, add or drop columns, change column data types. B.) Adding a column to the table To add a column, you can use ADD clause: ADD [COLUMN] col_definition [FIRST | AFTER col_name] Example: ALTER TABLE tblstudent ADD sex enum(‘F’,’M’); ALTER TABLE tblstudent add phone char(20) after sex; C.) Deleting any column from the table To delete any column, you use DROP clause: DROP [COLUMN] col_name example: ALTER TABLE tblstudent DROP sex;

Managing Databases and Tables 7.) Altering Table Structure You can also use ALTER TABLE to rename tables, add or drop columns, change column data types, D.) Renaming a table Use a RENAME clause that specifies the new table name: ALTER TABLE tbl_name RENAME TO new_tbl_name; Another way to rename tables is with RENAME TABLE. The syntax looks like this: RENAME TABLE old_name TO new_name; Note: One thing that RENAME TABLE can do that ALTER TABLE cannot is rename multiple tables in the same statement. For example, you can swap the names of two tables like this: RENAME TABLE t1 TO tmp, t2 TO t1, tmp TO t2; Example: ALTER TABLE sampdb.tbl RENAME TO sampdb.tbl1; RENAME TABLE sampdb.tbl TO sampdb.tbl1;

Selecting, Inserting, Deleting, and Updating Data 1.) Using INSERT The INSERT SQL statement is used to insert rows into a table. Some sample insert statements are shown below: use employee; delete from department; insert into department values(42, 'Finance'), (128, 'Research and Development'), (NULL, 'Human Resources'), (NULL, 'Marketing'); 2.) Using DELETE The DELETE SQL statement allows us to delete rows from a table. There are some delete statements shown below: delete from department; delete from department where name='Asset Management' ;

Selecting, Inserting, Deleting, and Updating Data 3.) Using UPDATE We can use the UPDATE SQL statement to change rows already stored in the database. For example, imagine that one of our employees changes jobs: update employee set job='DBA‘ where employeeID='6651'; 4.) Using SELECT The SELECT statement has the following general form: SELECT columns FROM tables [WHERE conditions] [GROUP BY group [HAVING group_conditions]] [ORDER BY sort_columns] [LIMIT limits];

Selecting, Inserting, Deleting, and Updating Data Example of Select statement: a.) select employeeID, name from employee where job='Programmer'; b.) select distinct job from employee; c.) select count(*), job from employee group by job desc; d.) select count(*), job from employee group by job having count(*)=1; e.) select * from employee order by job asc, name desc; f.) select * from employeeSkills limit 5; g.) select * from employeeSkills limit 5, 3;

The end of Chapter 5 Thanks for your paying attention