Basics of SQL
An Introduction to Structured Query
Language
What is SQL?
• SQL stands for Structured Query Language.
• It is used to communicate with databases.
• SQL is the standard language for Relational
Database Management Systems (RDBMS).
• It is used for storing, manipulating, and
retrieving data in databases.
Common SQL Commands
• SELECT – retrieve data from a database
• INSERT – insert new data into a table
• UPDATE – modify existing data
• DELETE – remove data
• CREATE – create new tables or databases
• DROP – delete tables or databases
SELECT Statement
• Used to retrieve data from a table:
• Syntax:
• SELECT column1, column2 FROM table_name;
• Example:
• SELECT name, age FROM employees;
WHERE Clause
• Used to filter records:
• Syntax:
• SELECT * FROM table_name WHERE
condition;
• Example:
• SELECT * FROM employees WHERE age > 30;
INSERT INTO Statement
• Used to add new rows to a table:
• Syntax:
• INSERT INTO table_name (column1, column2)
VALUES (value1, value2);
• Example:
• INSERT INTO employees (name, age) VALUES
('Alice', 28);
UPDATE Statement
• Used to modify existing records:
• Syntax:
• UPDATE table_name SET column1 = value1
WHERE condition;
• Example:
• UPDATE employees SET age = 29 WHERE name
= 'Alice';
DELETE Statement
• Used to remove existing records:
• Syntax:
• DELETE FROM table_name WHERE condition;
• Example:
• DELETE FROM employees WHERE name =
'Alice';
SQL Clauses
• WHERE – filters records
• ORDER BY – sorts results
• GROUP BY – groups rows sharing properties
• HAVING – filters groups
• LIMIT – restricts the number of rows returned