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.

Slides:



Advertisements
Similar presentations
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Advertisements

Introduction to Structured Query Language (SQL)
Structured Query Language Part I Chapter Three CIS 218.
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.
Concepts of Database Management Sixth Edition
SQL Tutorials To understand some of the topics please analyze the following tutorials: The following tutorials will help:
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
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.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Microsoft Access 2010 Building and Using Queries.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Sundara Ram Matta Apr 01 st, Sundara Ram Matta Apr 01 st, 2015
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
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.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Maintaining a Database Access Project 3. 2 What is Database Maintenance ?  Maintaining a database means modifying the data to keep it up-to-date. This.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Session 1 Module 1: Introduction to Data Integrity
INFANL01-3 ANALYSE 3 WEEK 3 March 2015 Institute voor Communication, Media en Informatietechnology.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
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.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Getting started with Accurately Storing Data
Fundamentals of DBMS Notes-1.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Chapter 5 Introduction to SQL.
Query Methods Where Clauses Start ….
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Introduction to Structured Query Language(SQL)
SQL Implementation & Administration
JDBC.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Introduction To Structured Query Language (SQL)
SQL DATA CONSTRAINTS.
Introduction To Structured Query Language (SQL)
Presentation transcript:

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 tables

Tables Tables are structure that are used to store information Each table consists of 1 or more fields For simplicity, each field name should be declared as a single word (ex.: username, user_nname, not User Name). This will avoid multiple errors and issues Each table should have a field called id that should be defined as the primary key (the primary key uniquely defines each record in the table)

Primary Keys The PRIMARY KEY constraint uniquely identifies each record in a database table. Primary keys must contain UNIQUE values. A primary key column cannot contain NULL values. Most (in our case, ALL) tables should have a primary key, and each table can have only ONE primary key.

NOT NULL The NOT NULL constraint enforces a column to NOT accept NULL values The NOT NULL constraint enforces a field to always contain a value This means that you cannot insert a new record, or update a record without adding a value to this field

UNIQUE The UNIQUE constraint uniquely identifies each record in a database table The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it Note that you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table

DEFAULT The DEFAULT constraint is used to insert a default value into a column The default value will be added to all new records, if no other value is specified

Creating a table In order to create a new table using SQL queries, the following rule applies to generating the basic query: CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size),.... );

Database Table Queries There are 4 basic operators that are used where working on database table queries: SELECT INSERT UPDATE DELETE

Database Table Queries (continued) There are 4 basic components when constructing a table query: The operator (insert, update,…) The field(s) The table The condition

Database Table Queries (SELECT query) SELECT column_name,column_name FROM table_name; Select * from table; (retrieves all entries in table) Select id, username from table; (retrieves id and username of each entry in table) Select id, username from table where username like ‘ab%cd’; (retrieves id and username of each entry in table where the username starts with ‘ab’ and ends with ‘cd’) Select id, username from table where username like ‘%cd’; (retrieves id and username of each entry in table where the username ends with ‘cd’) …

Database Table Queries (DELETE query) DELETE FROM table_name WHERE some_column=some_value; Delete from table where id = value; (deletes the table entry with id = value)

Database Table Queries (UPDATE query) UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value; Update users set password=‘12345’; (updates all entries in the users table and sets the password to ‘12345’ for each entry) Update users set password=‘12345’ where id=1; (updates the entry in the users table where the id = 1 and sets its password to ‘12345’)

Database Table Queries (INSERT query) INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...); For the inserted entry: Column1 will have the value1 Column2 will have the value2 Column3 will have the value3

Database Table Queries (INSERT query continued) INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...), (value11,value12,value13,...); For the 1 st inserted entry: Column1 will have the value1 Column2 will have the value2 Column3 will have the value3 For the 2 nd inserted entry: Column1 will have the value11 Column2 will have the value12 Column3 will have the value13

Using multiples within a single query (JOIN) An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them SELECT table1.column_name1, table2.column_name2, table1.column_name3 FROM table1 JOIN table2 ON table1.key_column_name1=table2.key_column_name2;

Using multiples within a single query (JOIN continued) You can join as many tables as you need Each join clause MUST be clearly defined in the ON section of the clause Ex.: SELECT * FROM users JOIN persInfo ON users.id = persInfo.userId

Grouping the resultset from a query When selecting entries from a database table, it is sometimes necessary to group certain entries together. This can be accomplished by using the GROUP BY statement The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns

Grouping the resultset from a query (continued) Ex.: SELECT persInfo.first_name, SUM( sales.sale ) FROM sales JOIN persInfo on sales.userId=persInfo.userId GROUP BY userId; Returns the first name (from the persInfo table) and the total sum of sales (calculated from the sale table) for each different userId

Condition statements (AND & OR) The AND & OR operators are used to filter records based on more than one condition The AND operator displays a record if both the first condition AND the second condition are true The OR operator displays a record if either the first condition OR the second condition is true

Condition statements (LIKE) The LIKE operator is used in a WHERE clause to search for a specified pattern in a column In SQL, wildcard characters are used with the SQL LIKE operator A wildcard character can be used to substitute for any other character(s) in a string WildcardDescription %A substitute for zero or more characters

Condition statements (BETWEEN) The BETWEEN operator selects values within a range The values can be numbers, text, or dates