Sunteți pe pagina 1din 4

CHAPTER 1

As explained, it is the database software


What Is a Database?
(DBMS or Database Management
The term database is used in many different
System) that actually does all the work
ways, but for our purposes a database
of storing, retrieving, managing, and
is a collection of data stored in some
manipulating data. MySQL is a DBMS;
organized fashion. The simplest way to
that is, it is database software.
think of it is to imagine a database as
a filing cabinet. The filing cabinet is Here are some of the reasons Why do so
simply a physical location to store
many organization and developers use
data, regardless of what that data is or
MYSQL:
how it is organized.
Database- A container (usually a file or set of

Cost MySQL is open-source, and is


files) to store organized data.
usually free to use (and even modify) the
Database software is actually called the
software without paying for it.
Database Management System (or
DBMS). The database is the container

Performance MySQL is fast (make


created and manipulated via the
that very fast).
DBMS.
In the database world, that file is called a
table. A table is a structured file that

Trusted MySQL is used by some of


can store data of a specific type. A
the most important and prestigious
table might contain a list of
organizations and sites, all of whom entrust
customers, a product catalog, or any
it with their critical data.
other list of information.
Table -A structured list of data of a specific

Simplicity MySQL is easy to install


type.
and get up and running.
Column- A single field in a table. All tables
are made up of one or more columns.
Datatype- A type of allowed data. Every table DBMSs fall into two categories: shared
filebased and client-server.
column has an associated datatype
that restricts (or allows) specific data MySQL is a client-server DBMS.Every
MySQL installation comes with a
in that column.
simple command-line utility called
Data- in a table is stored in rows;
Row- A record in a table.
mysql.
Primary Key -A column (or set of columns) CHAPTER 3
whose values uniquely identify every MySQL Administrator is a graphical
row in a table.
interactive client designed to simplify
Any column in a table can be established as
the administration of MySQL servers.
the primary key, as long as it meets
the following conditions:

Server Information displays


-1.)(No two rows can have the same primary
status and version information about the
key value.
connected server and client.
-2.)Every row must have a primary key value
(primary key columns may not allow
NULL values).

Service Control allows you to

CHAPTER 2
What Is SQL?

SQL (pronounced as the letters S-Q-L or as


sequel)
is
an
abbreviation
for
Structured Query Language. SQL is a
language designed specifically for
communicating with databases.

stop and start MySQL as well as specify


server features.

User Administration is used to


define MySQL users, logins, and privileges.

Catalogs lists available databases


and allows for the creation of databases and
tables.

What are the advantages of SQL?


1.) SQL is not a proprietary language used
To connect to MySQL you need the following
by specific database vendors.
2.) SQL is easy to learn.
pieces of information:
3.) SQL is actually a very powerful
language

The hostname (the name of the


computer)this is localhost if connecting to
a local MySQL server

Sorting multiple columns syntax:

The port (if a port other than the


default 3306 is used)

Sorting for Direction syntax:

A valid user name.

The user password (if required)

SELECT
prod_id,
prod_price,
prod_name
FROM products
ORDER BY prod_price DESC;

Syntax for limit:

The USE statement does not return any


results.
the MySQL SHOW command is used to display
this information (information which
MySQL then extracts from those
internal tables).
SHOW DATABASES; returns a list of available
databases.
SHOW TABLES; To obtain a list of tables within
a database

SELECT
prod_id,
prod_price,
prod_name
FROM products
ORDER BY prod_price, prod_name;

SELECT prod_price
FROM products
ORDER BY prod_price DESC
LIMIT 1;

CHAPTER 6: FILTERING DATA


WHERE CLAUSE
OPERATOR

Equality

<>

Nonequality

!=

Nonequality

<

Less than

<=

Less than or equal to

We'll start with a simple SQL SELECT


statement, as follows:
Input

>

Greater than

SELECT prod_name
FROM products;
SELECT statement to retrieve a single
column called prod_name from the products

>=

Greater than or equal to

BETWEEN

Between two specified values

CHAPTER 4 Retrieving Data


learn how to use the SELECT statement
to retrieve one or more columns of data from
a table.
The SQL statement you'll probably use
most frequently is the SELECT statement. Its
purpose is to retrieve information from one
or more tables.
To use SELECT to retrieve table data
you must, at a minimum, specify two pieces
of informationwhat you want to select, and
from where you want to select it.

table
Retrieving All Columns

SELECT statements can also request all


columns without having to list them
individually. This is done using the asterisk
(*) wildcard character in lieu of actual
column name.

wildcard (*) is specified, all the


columns in the table are returned.
CHAPTER 5: SORTING RETRIEVED DATA
Clause SQL statements are made up of
clauses, some required and some optional.

Syntax:

SELECT prod_name
FROM products
ORDER BY prod_name;

SELECT prod_name, prod_price


FROM products
WHERE prod_price < 10;
CHAPTER 7:ADVANCED DATA

FILTERING
Operator A special keyword used to join or
change clauses within a WHERE clause. Also
known as logical operators.

NOT A keyword used in a WHERE clause to

negate a condition.
SELECT prod_name, prod_price
FROM products
WHERE vend_id NOT IN (1002,1003)
ORDER BY prod_name;

CHAPTER 8:
The most frequently used wildcard is the
percent sign (%). Within a search string, %
means match any number of occurrences of
any character.
SELECT prod_id, prod_name
FROM products
WHERE prod_name LIKE '%anvil%';
CHAPTER 9:

Repetition Metacharacters

CHAPTER 10: CALCULATING FIELDS


SELECT prod_id,
quantity,
item_price,
quantity*item_price AS
expanded_price
FROM orderitems
WHERE order_num = 20005;

MySQL Mathematical Operators

Operator

Description

Addition

Subtraction

Multiplication

Division

CHAPTER 11:
Text functions are used to manipulate
strings of text (for example, trimming
or padding values and converting
values to upper- and lowercase).
Numeric functions are used to perform
mathematical operations on numeric
data (for example, returning absolute
numbers and performing algebraic
calculations).

Date and time functions are used to


manipulate date and time values and
to extract specific components from
these values (for example, returning
differences between dates and
checking date validity).
System functions return information
specific to the DBMS being used (for
example, returning user login
information or checking version
specifics).
SYNTAX:
SELECT vend_name,
UPPER(vend_name) AS
vend_name_upcase
FROM vendors
ORDER BY vend_name;
The AVG() Function
AVG() is used to return the average
value of a specific column by counting
both the number of rows in the table
and the sum of their values. AVG()
can be used to return the average
value of all columns or of specific
columns or rows.
SYNTAX:
SELECT AVG(prod_price) AS avg_price
FROM products;
NULL Values Column rows containing
NULL values are ignored by the AVG()
function.
The COUNT() Function
COUNT() does just that: It counts. Using
COUNT(), you can determine the

number of rows in a table or the


number of rows that match a specific
criterion.
COUNT() can be used two ways:
Use COUNT(*) to count the number of
rows in a table, whether columns
contain values or NULL values.
Use COUNT(column) to count the
number of rows that have values in a
specific column, ignoring NULL values.

This first example returns the total number


of customers in the customers table:
Input
SELECT COUNT(*) AS num_cust

FROM customers;
CHAPTER 13:
Groups are created using the GROUP
BY clause in your SELECT statement.
SELECT vend_id, COUNT(*) AS
num_prods
FROM products
GROUP BY vend_id;

SELECT CLAUSES AND SEQUENCE


CHAPTER 14:

To perform that COUNT(*) calculation for


each customer, use COUNT* as a subquery.
Look at the following code:
Input
SELECT cust_name,
cust_state,
(SELECT COUNT(*)
FROM orders
WHERE orders.cust_id =
customers.cust_id) AS orders
FROM customers
ORDER BY cust_name;
CHAPTER 15: JOINING TABLES

Why Use Joins?


breaking data into multiple tables
enables more efficient storage, easier
manipulation, and greater scalability.
But these benefits come with a price.

To perform this operation, follow these


steps:
1. Retrieve the list of customers from the
customers table.
2. For each customer retrieved, count the
number of associated orders in the
orders table.
SELECT COUNT(*) AS orders
FROM orders
WHERE cust_id = 10001;

SELECT vend_name, prod_name,


prod_price
FROM vendors, products
WHERE vendors.vend_id =
products.vend_id
ORDER BY vend_name, prod_name;
SELECT vend_name, prod_name,
prod_price
FROM vendors INNER JOIN products
ON vendors.vend_id =
products.vend_id;

S-ar putea să vă placă și