0% found this document useful (0 votes)
8 views

Mysql

The document provides an overview of MySQL, a relational database management system, including its definition, types of databases, and SQL functionalities. It covers essential SQL commands such as CREATE, INSERT, SELECT, UPDATE, and DELETE, along with explanations of data types and the structure of database tables. Additionally, it highlights the importance of MySQL in various applications and its compliance with ANSI SQL standards.

Uploaded by

Ali Muzzammil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Mysql

The document provides an overview of MySQL, a relational database management system, including its definition, types of databases, and SQL functionalities. It covers essential SQL commands such as CREATE, INSERT, SELECT, UPDATE, and DELETE, along with explanations of data types and the structure of database tables. Additionally, it highlights the importance of MySQL in various applications and its compliance with ANSI SQL standards.

Uploaded by

Ali Muzzammil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

MySQL

by Muzzamil Arain (BS Cyber Security)

Muzzamil Arain 1
Database
A database is a structured collection of data. It's organized to allow for efficient storage, retrieval, and management

of information.

Types of Databases
• Relational Databases

Store data in tables with relationships between them, offering a structured approach.

• NoSQL Databases

Offer more flexibility in data structures, suitable for unstructured and semi-structured data.

• Other Types

Other types include graph databases, object-oriented databases, and document databases.

Muzzamil Arain 2
What is SQL?
• SQL stands for Structured Query Language

• SQL lets you access and manipulate databases

• SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International

Organization for Standardization (ISO) in 1987

What Can SQL do?


• SQL can execute queries against a database

• SQL can retrieve data from a database

• SQL can insert records in a database

• SQL can update records in a database

• SQL can delete records from a database

• SQL can create new databases

• SQL can create new tables in a database

• SQL can create stored procedures in a database

• SQL can create views in a database

• SQL can set permissions on tables, procedures, and views

Muzzamil Arain 3
What is MySQL?
• MySQL is a relational database management system

• MySQL is open-source

• MySQL is free

• MySQL is ideal for both small and large applications

• MySQL is very fast, reliable, scalable, and easy to use

• MySQL is cross-platform

• MySQL is compliant with the ANSI SQL standard

• MySQL was first released in 1995

• MySQL is developed, distributed, and supported by Oracle Corporation

• MySQL is named after co-founder Ulf Michael "Monty" Widenius's daughter: My

Who Uses MySQL?


• Huge websites like Facebook, Twitter, Airbnb, Booking.com, Uber, GitHub, YouTube, etc.

• Content Management Systems like WordPress, Drupal, Joomla!, Contao, etc.

• A very large number of web developers around the world

Muzzamil Arain 4
What is RDBMS?
RDBMS stands for Relational Database Management System.

RDBMS is a program used to maintain a relational database.

RDBMS is the basis for all modern database systems such as MySQL, Microsoft SQL Server, Oracle, and Microsoft

Access.

RDBMS uses SQL queries to access the data in the database.

What is a Database Table?


A table is a collection of related data entries, and it consists of columns and rows.

A column holds specific information about every record in the table.

A record (or row) is each individual entry that exists in a table.

Muzzamil Arain 5
CustomerID CustomerName ContactNo City Country

1 Ahmad 32423423 Karachi Pakistan

2 Bilal 34534453 Lahore Pakistan

3 Akash 34534532 Mumbai India

4 Akaay 63453345 Delhi India

5 Joseph 34534565 London England

Muzzamil Arain 6
The MySQL CREATE DATABASE Statement
The CREATE DATABASE statement is used to create a new SQL database.

Syntax
CREATE DATABASE databasename;

CREATE DATABASE Example


The following SQL statement creates a database called "testDB":

Example
CREATE DATABASE testDB;

Tip: Make sure you have admin privilege before creating any database. Once a database is created, you can check

it in the list of databases with the following SQL command: SHOW DATABASES;

Muzzamil Arain 7
The MySQL CREATE TABLE Statement
The CREATE TABLE statement is used to create a new table in a database.

Syntax
CREATE TABLE table_name (

column1 datatype,

column2 datatype,

column3 datatype,

....

);

The column parameters specify the names of the columns of the table.

The datatype parameter specifies the type of data the column can hold (e.g. varchar, integer, date, etc.).

Muzzamil Arain 8
MySQL Data Types
Each column in a database table is required to have a name and a data type.

An SQL developer must decide what type of data that will be stored inside each column when creating a table. The

data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also

identifies how SQL will interact with the stored data.

In MySQL there are three main data types: string, numeric, and date and time.

Muzzamil Arain 9
MySQL Data Types
String Data Types

DataType Description

CHAR(size) A FIXED length string (can contain letters, numbers, and special characters). The size

parameter specifies the column length in characters - can be from 0 to 255. Default is 1

VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and special characters). The size

parameter specifies the maximum column length in characters - can be from 0 to 65535

BINARY(size) Equal to CHAR(), but stores binary byte strings. The size parameter specifies the column length

in bytes. Default is 1

TEXT(size) Holds a string with a maximum length of 65,535 bytes

TINYTEXT Holds a string with a maximum length of 255 characters

MEDIUMTEXT Holds a string with a maximum length of 16,777,215 characters

MEDIUMBLOB For BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data

LONGTEXT Holds a string with a maximum length of 4,294,967,295 characters

Muzzamil Arain 10
MySQL Data Types
Numeric Data Types

DataType Description

BIT(size) A bit-value type. The number of bits per value is specified in size. The size parameter can hold a

value from 1 to 64. The default value for size is 1.

TINYINT(size) A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to 255. The size

parameter specifies the maximum display width (which is 255)

BOOL/BOOLEAN Zero is considered as false, nonzero values are considered as true.

SMALLINT(size) A small integer. Signed range is from -32768 to 32767. Unsigned range is from 0 to 65535. The

size parameter specifies the maximum display width (which is 255)

MEDIUMINT(size) A medium integer. Signed range is from -8388608 to 8388607. Unsigned range is from 0 to

16777215. The size parameter specifies the maximum display width (which is 255)

INT/INTEGER(size A medium integer. Signed range is from -2147483648 to 2147483647. Unsigned range is from 0

) to 4294967295. The size parameter specifies the maximum display width (which is 255)

BIGINT(size) A large integer. Signed range is from -9223372036854775808 to 9223372036854775807.

Unsigned range is from 0 to 18446744073709551615. The size parameter specifies the

maximum display width (which is 255)

FLOAT(p) A floating point number. MySQL uses the p value to determine whether to use FLOAT or DOUBLE

for the resulting data type. If p is from 0 to 24, the data type becomes FLOAT(). If p is from 25 to

53, the data type becomes DOUBLE()

DOUBLE(size, d) A normal-size floating point number. The total number of digits is specified in size. The number of

digits after the decimal point is specified in the d parameter

DECIMAL/DEC(si An exact fixed-point number. The total number of digits is specified in size. The number of digits

ze, d) after the decimal point is specified in the d parameter. The maximum number for size is 65. The

maximum number for d is 30. The default value for size is 10. The default value for d is 0.

Muzzamil Arain 11
MySQL Data Types
Date and Time Data Types

DataType Description

DATE A date. Format: YYYY-MM-DD. The supported range is from '1000-01-01' to '9999-12-31'

DATETIME(fsp) A date and time combination. Format: YYYY-MM-DD hh:mm:ss. The supported range is from

'1000-01-01 00:00:00' to '9999-12-31 23:59:59'. Adding DEFAULT and ON UPDATE in the column

definition to get automatic initialization and updating to the current date and time

TIMESTAMP(fsp) A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch

('1970-01-01 00:00:00' UTC). Format: YYYY-MM-DD hh:mm:ss. The supported range is from

'1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC. Automatic initialization and updating

to the current date and time can be specified using DEFAULT CURRENT_TIMESTAMP and ON

UPDATE CURRENT_TIMESTAMP in the column definition

TIME(fsp) A time. Format: hh:mm:ss. The supported range is from '-838:59:59' to '838:59:59'

YEAR A year in four-digit format. Values allowed in four-digit format: 1901 to 2155, and 0000.

MySQL 8.0 does not support year in two-digit format.

Muzzamil Arain 12
The MySQL INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a table.

INSERT INTO Syntax


It is possible to write the INSERT INTO statement in two ways:

1. Specify both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3, ...)

VALUES (value1, value2, value3, ...);

2. If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL

query. However, make sure the order of the values is in the same order as the columns in the table. Here, the

INSERT INTO syntax would be as follows:

INSERT INTO table_name

VALUES (value1, value2, value3, ...);

INSERT INTO Example


The following SQL statement inserts a new record in the "Customers" table:

Example
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)

VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

Muzzamil Arain 13
The MySQL SELECT Statement
The SELECT statement is used to select data from a database.

The data returned is stored in a result table, called the result-set.

SELECT Syntax
SELECT column1, column2, ...

FROM table_name;

Here, column1, column2, ... are the field names of the table you want to select data from. If you want to select all the

fields available in the table, use the following syntax:

SELECT * FROM table_name;

The MySQL SELECT DISTINCT Statement


The SELECT DISTINCT statement is used to return only distinct (different) values.

Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different

(distinct) values.

SELECT DISTINCT Syntax


SELECT DISTINCT column1, column2, ...

FROM table_name;

Muzzamil Arain 14
The MySQL DROP DATABASE Statement
The DROP DATABASE statement is used to drop an existing SQL database.

Syntax
DROP DATABASE databasename;

Note: Be careful before dropping a database. Deleting a database will result in loss of complete information stored

in the database!

DROP DATABASE Example


The following SQL statement drops the existing database "testDB":

Example
DROP DATABASE testDB;

Muzzamil Arain 15
The following example creates a table called "Persons" that contains five columns: PersonID, LastName,

FirstName, Address, and City:

Example
CREATE TABLE Persons (

PersonID int,

LastName varchar(255),

FirstName varchar(255),

Address varchar(255),

City varchar(255)

);

Muzzamil Arain 16
The MySQL DROP TABLE Statement
The DROP TABLE statement is used to drop an existing table in a database.

Syntax
DROP TABLE table_name;

Note: Be careful before dropping a table. Deleting a table will result in loss of complete information stored in the

table!

MySQL DROP TABLE Example


The following SQL statement drops the existing table "Shippers":

Example
DROP TABLE Shippers;

MySQL TRUNCATE TABLE


The TRUNCATE TABLE statement is used to delete the data inside a table, but not the table itself.

Syntax
TRUNCATE TABLE table_name;

Muzzamil Arain 17
The MySQL WHERE Clause
The WHERE clause is used to filter records.

It is used to extract only those records that fulfill a specified condition.

WHERE Syntax
SELECT column1, column2, ...

FROM table_name

WHERE condition;

Note: The WHERE clause is not only used in SELECT statements, it is also used in UPDATE, DELETE, etc.!

Muzzamil Arain 18
The MySQL AND, OR and NOT Operators
The WHERE clause can be combined with AND, OR, and NOT operators.

The AND and OR operators are used to filter records based on more than one condition:

• The AND operator displays a record if all the conditions separated by AND are TRUE.

• The OR operator displays a record if any of the conditions separated by OR is TRUE.

The NOT operator displays a record if the condition(s) is NOT TRUE.

AND Syntax
SELECT column1, column2, ...

FROM table_name

WHERE condition1 AND condition2 AND condition3 ...;

Muzzamil Arain 19
The MySQL AND, OR and NOT Operators

OR Syntax
SELECT column1, column2, ...

FROM table_name

WHERE condition1 OR condition2 OR condition3 ...;

NOT Syntax
SELECT column1, column2, ...

FROM table_name

WHERE NOT condition;

Muzzamil Arain 20
The MySQL ORDER BY Keyword
The ORDER BY keyword is used to sort the result-set in ascending or descending order.

The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order,
use the DESC keyword.

ORDER BY Syntax
SELECT column1, column2, ...

FROM table_name

ORDER BY column1, column2, ... ASC|DESC;

ORDER BY Several Columns Example


The following SQL statement selects all customers from the "Customers" table, sorted by the "Country" and the

"CustomerName" column. This means that it orders by Country, but if some rows have the same Country, it orders

them by CustomerName:

Example
SELECT * FROM Customers

ORDER BY Country, CustomerName;

Muzzamil Arain 21
The MySQL UPDATE Statement
The UPDATE statement is used to modify the existing records in a table.

UPDATE Syntax
UPDATE table_name

SET column1 = value1, column2 = value2, ...

WHERE condition;

Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement. The WHERE
clause specifies which record(s) that should be updated. If you omit the WHERE clause, all records in the table will
be updated!

UPDATE Multiple Records


It is the WHERE clause that determines how many records will be updated.

The following SQL statement will update the PostalCode to 00000 for all records where country is "Mexico":

Example
UPDATE Customers

SET PostalCode = 00000

WHERE Country = 'Mexico';

Muzzamil Arain 22
The MySQL DELETE Statement
The DELETE statement is used to delete existing records in a table.

DELETE Syntax
DELETE FROM table_name WHERE condition;

Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE
clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records in the table will be
deleted!

Muzzamil Arain 23
The MySQL LIMIT Clause
The LIMIT clause is used to specify the number of records to return.

The LIMIT clause is useful on large tables with thousands of records. Returning a large number of records can
impact performance.

LIMIT Syntax
SELECT column_name(s)

FROM table_name

WHERE condition

LIMIT number;

Muzzamil Arain 24
MySQL MIN() and MAX() Functions
The MIN() function returns the smallest value of the selected column.

The MAX() function returns the largest value of the selected column.

MIN() Syntax
SELECT MIN(column_name)

FROM table_name

WHERE condition;

MAX() Syntax
SELECT MAX(column_name)

FROM table_name

WHERE condition;

Muzzamil Arain 25
MySQL COUNT(), AVG() and SUM() Functions
The COUNT() function returns the number of rows that matches a specified criterion.

COUNT() Syntax
SELECT COUNT(column_name)

FROM table_name

WHERE condition;

The AVG() function returns the average value of a numeric column.

AVG() Syntax
SELECT AVG(column_name)

FROM table_name

WHERE condition;

The SUM() function returns the total sum of a numeric column.

SUM() Syntax
SELECT SUM(column_name)

FROM table_name

WHERE condition;

Muzzamil Arain 26
The MySQL BETWEEN Operator
The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.

The BETWEEN operator is inclusive: begin and end values are included.

BETWEEN Syntax
SELECT column_name(s)

FROM table_name

WHERE column_name BETWEEN value1 AND value2;

Muzzamil Arain 27
The MySQL IN Operator
The IN operator allows you to specify multiple values in a WHERE clause.

The IN operator is a shorthand for multiple OR conditions.

IN Syntax
SELECT column_name(s)

FROM table_name

WHERE column_name IN (value1, value2, ...);

or:

SELECT column_name(s)

FROM table_name

WHERE column_name IN (SELECT STATEMENT);

Muzzamil Arain 28
Symbol Description Example
MySQL Wildcard Characters
% Represents zero bl% finds bl, black,
A wildcard character is used to substitute one or more

or more blue, and blob


characters in a string.

characters

Wildcard characters are used with the LIKE operator.


The LIKE operator is used in a WHERE clause to _ Represents a h_t finds hot, hat,

search for a specified pattern in a column. single character and hit

Wildcard Characters in
MySQL»»»

Muzzamil Arain 29
The MySQL LIKE Operator
Like Operator Description

WHERE CustomerName LIKE 'a%' Finds any values that start with "a"

WHERE CustomerName LIKE '%a' Finds any values that end with "a"

WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position

WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second position

WHERE CustomerName LIKE 'a_%' Finds any values that start with "a" and are at least 2 characters in length

WHERE CustomerName LIKE 'a__%' Finds any values that start with "a" and are at least 3 characters in length

WHERE ContactName LIKE 'a%o' Finds any values that start with "a" and ends with "o"

WHERE CustomerName LIKE 'a_%_%' Finds any values that starts with "a" and are at least 3 characters in length

Muzzamil Arain 30
MySQL Wildcard Characters
The MySQL LIKE Operator
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

There are two wildcards often used in conjunction with the LIKE operator:

• The percent sign (%) represents zero, one, or multiple characters

• The underscore sign (_) represents one, single character

The percent sign and the underscore can also be used in combinations!

LIKE Syntax
SELECT column1, column2, ...

FROM table_name

WHERE columnN LIKE pattern;

Tip: You can also combine any number of conditions using AND or OR operators.

Muzzamil Arain 31
MySQL ALTER TABLE Statement
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

The ALTER TABLE statement is also used to add and drop various constraints on an existing table.

ALTER TABLE - ADD Column


To add a column in a table, use the following syntax:

ALTER TABLE table_name

ADD column_name datatype;

The following SQL adds an "Email" column to the "Customers" table:

Example
ALTER TABLE Customers

ADD Email varchar(255);

Muzzamil Arain 32
ALTER TABLE - DROP COLUMN
To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a

column):

ALTER TABLE table_name

DROP COLUMN column_name;

ALTER TABLE - MODIFY COLUMN


To change the data type of a column in a table, use the following syntax:

ALTER TABLE table_name

MODIFY COLUMN column_name datatype;

Muzzamil Arain 33
MySQL Constraints
SQL constraints are used to specify rules for the data in a table.

Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the

data in the table. If there is any violation between the constraint and the data action, the action is aborted.

Constraints can be column level or table level. Column level constraints apply to a column, and table level

constraints apply to the whole table.

The following constraints are commonly used in SQL:

• NOT NULL - Ensures that a column cannot have a NULL value

• UNIQUE - Ensures that all values in a column are different

• PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table

• FOREIGN KEY - Prevents actions that would destroy links between tables

• CHECK - Ensures that the values in a column satisfies a specific condition

• DEFAULT - Sets a default value for a column if no value is specified

• CREATE INDEX - Used to create and retrieve data from the database very quickly

Muzzamil Arain 34
MySQL Constraints
Create Constraints
Constraints can be specified when the table is created with the CREATE TABLE statement, or after the table is
created with the ALTER TABLE statement.

Syntax
CREATE TABLE table_name (

column1 datatype constraint,

column2 datatype constraint,

column3 datatype constraint,

....

);

Muzzamil Arain 35
MySQL NOT NULL Constraint
By default, a column can hold NULL values.

The NOT NULL constraint enforces a column to NOT accept NULL values.

This enforces a field to always contain a value, which means that you cannot insert a new record, or update a

record without adding a value to this field.

NOT NULL on CREATE TABLE


The following SQL ensures that the "ID", "LastName", and "FirstName" columns will NOT accept NULL values when

the "Persons" table is created:

Example
CREATE TABLE Persons (

ID int NOT NULL,

LastName varchar(255) NOT NULL,

FirstName varchar(255) NOT NULL,

Age int

);

Muzzamil Arain 36
MySQL NOT NULL Constraint
NOT NULL on ALTER TABLE
To create a NOT NULL constraint on the "Age" column when the "Persons" table is already created, use the
following SQL:

Example
ALTER TABLE Persons

MODIFY Age int NOT NULL;

Muzzamil Arain 37
MySQL UNIQUE Constraint
The UNIQUE constraint ensures that all values in a column are different.

Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of
columns.

A PRIMARY KEY constraint automatically has a UNIQUE constraint.

However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.

UNIQUE Constraint on CREATE TABLE


The following SQL creates a UNIQUE constraint on the "ID" column when the "Persons" table is created:

CREATE TABLE Persons (

ID int NOT NULL,

LastName varchar(255) NOT NULL,

FirstName varchar(255),

Age int,

UNIQUE (ID)

);

Muzzamil Arain 38
MySQL UNIQUE Constraint
UNIQUE Constraint on ALTER TABLE
To create a UNIQUE constraint on the "ID" column when the table is already created, use the following SQL:

ALTER TABLE Persons

ADD UNIQUE (ID);

DROP a UNIQUE Constraint


To drop a UNIQUE constraint, use the following SQL:

ALTER TABLE Persons

DROP INDEX UC_Person;

Muzzamil Arain 39
MySQL PRIMARY KEY Constraint
The PRIMARY KEY constraint uniquely identifies each record in a table.

Primary keys must contain UNIQUE values, and cannot contain NULL values.

A table can have only ONE primary key; and in the table, this primary key can consist of single or multiple columns

(fields).

PRIMARY KEY on CREATE TABLE


The following SQL creates a PRIMARY KEY on the "ID" column when the "Persons" table is created:

CREATE TABLE Persons (

ID int NOT NULL,

LastName varchar(255) NOT NULL,

FirstName varchar(255),

Age int,

PRIMARY KEY (ID)

);

Muzzamil Arain 40
MySQL PRIMARY KEY Constraint
PRIMARY KEY on ALTER TABLE
To create a PRIMARY KEY constraint on the "ID" column when the table is already created, use the following SQL:

ALTER TABLE Persons

ADD PRIMARY KEY (ID);

DROP a PRIMARY KEY Constraint


To drop a PRIMARY KEY constraint, use the following SQL:

ALTER TABLE Persons

DROP PRIMARY KEY;

Muzzamil Arain 41
MySQL FOREIGN KEY Constraint
The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables.

A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table.

The table with the foreign key is called the child table, and the table with the primary key is called the referenced or

parent table.

FOREIGN KEY on CREATE TABLE


The following SQL creates a FOREIGN KEY on the "PersonID" column when the "Orders" table is created:

CREATE TABLE Orders (

OrderID int NOT NULL,

OrderNumber int NOT NULL,

PersonID int,

PRIMARY KEY (OrderID),

FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)

);

Muzzamil Arain 42
MySQL FOREIGN KEY Constraint
FOREIGN KEY on ALTER TABLE
To create a FOREIGN KEY constraint on the "PersonID" column when the "Orders" table is already created, use the
following SQL:

ALTER TABLE Orders

ADD FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);

DROP a FOREIGN KEY Constraint


To drop a FOREIGN KEY constraint, use the following SQL:

ALTER TABLE Orders

DROP FOREIGN KEY FK_PersonOrder;

Muzzamil Arain 43
MySQL Dates
The most difficult part when working with dates is to be sure that the format of the date you are trying to insert,

matches the format of the date column in the database.

As long as your data contains only the date portion, your queries will work as expected. However, if a time portion is

involved, it gets more complicated.

MySQL Date Data Types


MySQL comes with the following data types for storing a date or a date/time value in the database:

• DATE - format YYYY-MM-DD

• DATETIME - format: YYYY-MM-DD HH:MI:SS

• TIMESTAMP - format: YYYY-MM-DD HH:MI:SS

• YEAR - format YYYY or YY

Note: The date data type are set for a column when you create a new table in your database!

SELECT * FROM Orders WHERE OrderDate='2008-11-11'

Muzzamil Arain 44
MySQL Aliases
Aliases are used to give a table, or a column in a table, a temporary name.

Aliases are often used to make column names more readable.

An alias only exists for the duration of that query.

An alias is created with the AS keyword.

Alias Column Syntax


SELECT column_name AS alias_name

FROM table_name;

Muzzamil Arain 45

You might also like