To SQL: A Guide To Mysql
To SQL: A Guide To Mysql
to SQL
A Guide to MySQL
Objectives
• Describe the basic commands and functions of SQL.
• Use SQL statements in creating, updating, and deleting
databases and tables.
• Use SQL aggregate functions in problem-solving.
• Integrate the database concepts learned into a project concept.
• Create models and incorporate SQL based on given
case/business rules.
A Guide to MySQL 2
Introduction
• Structured Query Language (SQL):
• Popular and widely used language for retrieving and manipulating
database data
A Guide to MySQL 3
Structured Query Language (SQL)
A database language allows you to
create database and table structures,
perform basic data management cores
(add, delete, modify) and perform complex
queries designed to transform the raw data
into useful information.
A Guide to MySQL 4
Two Categories of SQL Functions
1. Data Definition Language (DDL)
Examples: CREATE DATABASE, CREATE TABLE, ALTER TABLE, DROP TABLE, PRIMARY KEY, FOREIGN KEY
A Guide to MySQL 5
Two Categories of SQL Functions
2. Data Manipulation Language
A Guide to MySQL 6
Common SQL Data Types
A Guide to MySQL 7
Obtaining Help in MySQL
• help contents
• help union
A Guide to MySQL 8
A Guide to MySQL 9
Using MySQL Reference
Manual to Get Help
• Click MySQL Manual - Table of Contents on MySQL
4.1 submenu
A Guide to MySQL 10
A Guide to MySQL 11
Access the
MySQL
command line
with XAMPP
for Windows
A Guide to MySQL 12
A Guide to MySQL 13
Online Editor for SQL
https://paiza.io/en/projects/new?language=mysql
A Guide to MySQL 14
A Guide to MySQL 15
Basic SQL Statement: Creating a
Database
A Guide to MySQL 16
Creating a Database (continued)
A Guide to MySQL 17
Changing the Default Database
• Default database: database to which all subsequent
commands pertain
• USE command, followed by database name:
• Changes the default database
• Execute at the start of every session
A Guide to MySQL 19
Table and Column Name
Restrictions
• Names cannot exceed 18 characters
A Guide to MySQL 20
Creating the REP Table
A Guide to MySQL 21
Entering Commands in MySQL
• Commands are free-format; no rules stating specific words in specific
positions
A Guide to MySQL 22
Running SQL Commands
A Guide to MySQL 23
Editing SQL Commands
• Statement history: stores most recently used command
• Editing commands:
• Use arrow keys to move up, down, left, and right
• Use Ctrl+A to move to beginning of line
• Use Ctrl+E to move to end of line
• Use Backspace and Delete keys
A Guide to MySQL 24
Errors in SQL Commands
A Guide to MySQL 25
Editing MySQL Commands
• Press Up arrow key to go to top line
• If Enter is not pressed on a line, line not part of the revised command
A Guide to MySQL 26
Dropping a Table
• Can correct errors by dropping (deleting) a table and starting over
A Guide to MySQL 27
Nulls
• A special value to represent situation when actual value is not known
for a column
A Guide to MySQL 28
Implementation of Nulls
• Use NOT NULL clause in CREATE TABLE command to exclude the
use of nulls in a column
A Guide to MySQL 29
Adding Rows to a Table
• INSERT command:
• INSERT INTO followed by table name
• VALUES command followed by specific values in parentheses
• Values for character columns in single quotation marks
A Guide to MySQL 30
The Insert Command
A Guide to MySQL 31
Modifying the INSERT Command
A Guide to MySQL 32
Adding Additional Rows
A Guide to MySQL 33
The INSERT Command with
Nulls
• Use a special format of INSERT command to enter a null value in a
table
• Identify the names of the columns that accept non-null values, then list
only the non-null values after the VALUES command
A Guide to MySQL 34
The INSERT Command with Nulls
• Enter only non-null values
• Precisely indicate values you are entering by listing
the columns
A Guide to MySQL 35
The INSERT Command with Nulls
(continued)
A Guide to MySQL 36
Viewing Table Data
• Use SELECT command to display all the rows and columns in a table
A Guide to MySQL 37
Viewing Table Data
(continued)
A Guide to MySQL 38
Viewing Table Data
(continued)
A Guide to MySQL 39
Next Topic:
A Guide to MySQL 40
Summary
• Use MySQL Command Line Client window to enter commands
• Type \h or help to obtain help at the mysql> prompt
• Use MySQL Reference Manual for more detailed help
A Guide to MySQL 41
Summary (continued)
• Use the CREATE DATABASE command to create a database
A Guide to MySQL 42
Summary (continued)
• CHAR, VARCHAR, DATE, DECIMAL, INT and SMALLINT data
types
• Use INSERT command to add rows
• Use NOT Null clause to identify columns that cannot have a null value
• Use SELECT command to view data in a table
A Guide to MySQL 43
Summary (continued)
• Use UPDATE command to change the value in a column
• Use DELETE command to delete a row
• Use SHOW COLUMNS command to display a table’s structure
A Guide to MySQL 44
-end-
☺
A Guide to MySQL 45