MYSQL
MYSQL
QL
CMP 313
MYSQL
● SQL keywords are NOT case sensitive: select is the same as SELECT
MYSQL - Commands
● SELECT - extracts or gets data from a database
● UPDATE - updates or modify data in a database
● DELETE - deletes/removes data from a database
● INSERT INTO - inserts new data into a database
● CREATE DATABASE - creates a new database
● ALTER DATABASE - modifies a database
● CREATE TABLE - creates a new table
● ALTER TABLE - modifies a table
● DROP TABLE - deletes a table
● CREATE INDEX - creates an index (search key)
● DROP INDEX - deletes/removes an index
MYSQL - Commands
MySQL CREATE DATABASE Statement
Syntax:
Syntax:
Syntax:
SELECT column1, column2, ...
FROM table_name;
OR
Note: The WHERE clause is not only used in SELECT statements, it is also used in UPDATE, DELETE, etc.!
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!
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
MYSQL - Commands
MySQL DELETE Statement
Syntax:
EXAMPLE:
DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';
MYSQL - Commands
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.
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND/OR/NOT condition2 AND/OR/NOT condition3 ...;
MYSQL - Commands
MySQL INSERT INTO Statement
Syntax:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
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.
Syntax:
ALTER TABLE table_name
ADD column_name datatype;
MYSQL - Commands
MySQL INSERT INTO Statement
Syntax:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
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.
Syntax:
ALTER TABLE table_name
ADD column_name datatype;