Share This Tutorial

Views 22

Introduction to SQL (Structured Query Language)

Author Zak  |  Date 2024-10-15 18:08:04  |  Category Computer Science
Back Back

Introduction to SQL (Structured Query Language)

What is SQL?

SQL (Structured Query Language) is a standardized programming language designed for managing data in relational database management systems (RDBMS). It is used to perform various operations on data, including:

Basic SQL Commands

1. SELECT Statement

The SELECT statement is used to retrieve data from a database.

SELECT column1, column2, ...
FROM table_name;

Example:

SELECT name, age
FROM customers;

This statement retrieves the name and age columns from the customers table.

2. WHERE Clause

The WHERE clause is used to filter data based on specific conditions.

SELECT column1, column2, ...
FROM table_name
WHERE condition;

Example:

SELECT name, age
FROM customers
WHERE age > 25;

This statement retrieves the name and age columns from the customers table where the age is greater than 25.

3. INSERT Statement

The INSERT statement is used to add new records to a table.

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

Example:

INSERT INTO customers (name, age, city)
VALUES ('John Doe', 30, 'New York');

This statement inserts a new record into the customers table with the specified values for name, age, and city.

4. UPDATE Statement

The UPDATE statement is used to modify existing records in a table.

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

Example:

UPDATE customers
SET age = 31
WHERE name = 'John Doe';

This statement updates the age column to 31 for the record where name is 'John Doe'.

5. DELETE Statement

The DELETE statement is used to remove records from a table.

DELETE FROM table_name
WHERE condition;

Example:

DELETE FROM customers
WHERE age < 18;

This statement deletes all records from the customers table where the age is less than 18.

Conclusion

This is a basic introduction to SQL. There are many other commands and features available in SQL that are beyond the scope of this tutorial. You can learn more about SQL by exploring the following resources: