Introduction to SQL Commands.

Introduction to SQL Commands:

Sonu Lakra
3 min readAug 27, 2023

Structured Query Language (SQL) is a domain-specific language used to manage and manipulate relational databases. SQL commands allow you to interact with databases by performing tasks such as retrieving data, inserting new records, updating existing records, and deleting data. Here’s a comprehensive overview of some fundamental SQL commands:

  1. SELECT: The SELECT statement retrieves data from a database table. It allows you to specify which columns you want to retrieve and apply conditions for filtering results.

Example:

SELECT column1, column2
FROM table_name
WHERE condition;

2. INSERT: The INSERT statement adds new records to a database table.

Example:

INSERT INTO table_name (column1, column2)
VALUES (value1, value2);

3. UPDATE: The UPDATE statement modifies existing records in a database table.

Example:

UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;

4. DELETE: The DELETE statement removes records from a database table.

Example:

DELETE FROM table_name
WHERE condition;

5. CREATE TABLE: The CREATE TABLE statement is used to define a new database table, specifying the columns, data types, and constraints.

Example:

CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);

6. ALTER TABLE: The ALTER TABLE statement is used to modify an existing database table structure, such as adding or dropping columns.

Example:

ALTER TABLE table_name
ADD column_name datatype;

7. DROP TABLE: The DROP TABLE statement deletes an existing database table and its data.

Example:

DROP TABLE table_name;

8. WHERE: The WHERE clause is used to filter records based on specified conditions in SELECT, UPDATE, and DELETE statements.

Example:

SELECT column1, column2
FROM table_name
WHERE condition;

9. ORDER BY: The ORDER BY clause is used to sort the results of a SELECT statement in ascending or descending order based on specified columns.

Example:

SELECT column1, column2
FROM table_name
ORDER BY column1 ASC;

10. GROUP BY: The GROUP BY clause is used to group rows that share a common value in one or more columns and perform aggregate functions on them.

Example:

SELECT column1, COUNT(*)
FROM table_name
GROUP BY column1;

11. JOIN: The JOIN operation combines rows from multiple tables based on a related column.

Example:

SELECT column1, column2
FROM table1
JOIN table2 ON table1.column = table2.column;

12. INNER JOIN, LEFT JOIN, RIGHT JOIN: These are variations of the JOIN operation that control which rows are included in the result set.

  • INNER JOIN returns only matching rows from both tables.
  • LEFT JOIN returns all rows from the left table and matching rows from the right table.
  • RIGHT JOIN returns all rows from the right table and matching rows from the left table.

13. DISTINCT: The DISTINCT keyword is used to retrieve unique values from a column in the SELECT statement.

Example:

SELECT DISTINCT column1
FROM table_name;

Conclusion:

SQL commands are essential tools for working with relational databases. They allow you to manage data efficiently, retrieve information, and perform various data manipulation tasks. Understanding and mastering these commands is crucial for anyone working with databases or pursuing a career in data management or software development.

Introduction of SQL Commands

Website : https://limelook.link/

facebook : https://www.facebook.com/LimeLooksoftware

--

--