Relational databases are a type of database that stores data in tables with rows and columns. Each row represents a record, and each column represents a field or attribute. These tables are related to each other through shared values, forming a structured and organized system for storing and retrieving information.
SQL (Structured Query Language) is the standard language used to interact with relational databases. It provides a set of commands for defining, querying, and manipulating data within these databases.
Data Definition Language (DDL): Used to create, modify, and delete database objects.
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
FirstName VARCHAR(255),
LastName VARCHAR(255),
Email VARCHAR(255)
);
ALTER TABLE Customers
ADD COLUMN PhoneNumber VARCHAR(20);
DROP TABLE Customers;
Data Manipulation Language (DML): Used to insert, update, and delete data in tables.
INSERT INTO Customers (CustomerID, FirstName, LastName, Email)
VALUES (1, 'John', 'Doe', '[email protected]');
UPDATE Customers
SET Email = '[email protected]'
WHERE CustomerID = 1;
DELETE FROM Customers
WHERE CustomerID = 1;
Data Query Language (DQL): Used to retrieve data from tables.
SELECT * FROM Customers;
SELECT * FROM Customers
WHERE FirstName = 'John';
SELECT * FROM Customers
ORDER BY LastName;
SELECT Customers.FirstName, Orders.OrderID
FROM Customers
JOIN Orders ON Customers.CustomerID = Orders.CustomerID;
Relational databases and SQL are essential tools for storing, managing, and accessing data in a structured and organized manner. Understanding these concepts is crucial for working with databases and developing efficient data-driven applications.