Structured Query Language SQL Queries
Structured Query Language SQL Queries
QUERY LANGUAGE
(SQL QUERIES)
SQL queries are commands written in Structured Query
Language (SQL) that allow users to interact with databases. SQL
queries are used to perform various operations, such as retrieving,
inserting, updating, and deleting data.
SQL OPERATORS
In SQL, operators are symbols or keywords used to perform various
operations on data. These operations include comparisons, arithmetic
calculations, logical evaluations, and more.
SQL COMPARISON
OPERATORS
=: Checks if two values are equal.
Example: WHERE Age = 30
OR: Combines conditions and returns true if at least one condition is true.
Example: WHERE Age < 18 OR Age > 65
-: Subtraction.
Example: SELECT Salary - 2000 FROM Employees
*: Multiplication.
Example: SELECT Salary * 2 FROM Employees
/: Division.
Example: SELECT Salary / 2 FROM Employees
EXAMPLE:
INSERT INTO tblUsers (fName, mName, lName, Gender, Age, bMonth, bDay,
bYear)
VALUES ('Carlo', 'Bulan', 'Corpuz', 'Male', 17, 11, 9, 1997);
UPDATE QUERY
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
EXAMPLE:
UPDATE tblUsers
SET Age = 18, bMonth = 12
WHERE fName = 'Carlo' AND mName = 'Bulan' AND lName = 'Corpuz';
DELETE QUERY
This is used to delete records from a table.
DELETE QUERY
DELETE FROM table_name
WHERE condition;
EXAMPLE:
EXAMPLE:
ALTER TABLE tblUsers
ADD Email TEXT(255);
ALTER TABLE QUERY
Modifying an Existing Column (Changing Data Type)
ALTER TABLE table_name
ALTER COLUMN column_name new_data_type;
EXAMPLE:
ALTER TABLE tblUsers
ALTER COLUMN Gender TEXT(20);
ALTER TABLE QUERY
Deleting a Column
ALTER TABLE table_name
DROP COLUMN column_name;
EXAMPLE:
ALTER TABLE tblUsers
DROP COLUMN mName;
COUNT QUERY
The COUNT() function returns the number of rows that match a specified
condition.