Structured Query Language (SQL) is a standardized programming language specifically designed for managing and manipulating relational databases. Its primary uses revolve around interacting with data stored in a structured, tabular format.
Key uses of SQL include:
- Data Definition (DDL): SQL is used to define the structure of a database. This includes creating, modifying, and deleting database objects such as tables, indexes, and views.
Code
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50)
);
- Data Manipulation (DML): SQL enables the manipulation of data within the database. This involves inserting new data, updating existing data, and deleting data.
Code
INSERT INTO Customers (CustomerID, FirstName, LastName)
VALUES (1, 'John', 'Doe');
UPDATE Customers
SET FirstName = 'Jane'
WHERE CustomerID = 1;
DELETE FROM Customers
WHERE CustomerID = 1;
- Data Querying (DQL): SQL is most commonly used for retrieving data from the database based on specific criteria. This allows users to extract relevant information for analysis or display.
Code
SELECT FirstName, LastName
FROM Customers
WHERE LastName = 'Doe';
