SQL (Structured Query Language) is a standard language for managing and manipulating data in relational database management systems (RDBMS). It allows you to define, manipulate, and control access to data structured in tables.
Different types of SQL include: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, and INDEX.
Key Concepts:
The SELECT statement retrieves data from one or more tables. The SQL Wiki provides details on the different options.
Example: SELECT * FROM Customers;
The INSERT statement inserts new data into a table. It requires a 'values' clause to specify the data to insert.
Example: INSERT INTO Customers (Name, City) VALUES ('Alice', 'New York');
The UPDATE statement modifies existing data in a table. It requires a 'values' clause to specify the data to update.
Example: UPDATE Customers SET City = 'London' WHERE CustomerID = 1;
The DELETE statement removes data from a table. It requires a 'WHERE' clause to specify the rows to delete.
Example: DELETE FROM Customers WHERE CustomerID = 1;
The CREATE statement creates new tables in a database. It requires the table name and columns to be specified.
Example: CREATE TABLE Customers (CustomerID INT PRIMARY KEY, Name VARCHAR(255), City VARCHAR(255));
The ALTER statement modifies the structure of an existing table. It requires the table name and the attributes to modify.
Example: ALTER TABLE Customers ADD Email VARCHAR(255);
The DROP statement deletes a table. It requires the table name.
Example: DROP TABLE Customers;
The INDEX statement creates indexes on columns to speed up query performance.
Example: CREATE INDEX idx_Name ON Customers (Name);
The JOIN statement combines rows from two or more tables based on related columns.
Example: JOIN Customers ON Customers.CustomerID = Orders.CustomerID;