SQL

Database Language

SQL (Structured Query Language) is a standardized programming language designed for managing and manipulating relational databases. It allows users to create, read, update, and delete data, as well as define database structures and control access permissions.

Core SQL Operations (CRUD)

  • CREATE: Insert new data into tables
  • READ: Query and retrieve data from tables
  • UPDATE: Modify existing data in tables
  • DELETE: Remove data from tables

Basic SQL Commands

-- Create a table
CREATE TABLE employees (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    email VARCHAR(100),
    salary DECIMAL(10,2)
);

-- Insert data
INSERT INTO employees (id, name, email, salary)
VALUES (1, 'John Doe', 'john@example.com', 75000);

-- Query data
SELECT name, salary 
FROM employees 
WHERE salary > 50000;

-- Update data
UPDATE employees 
SET salary = 80000 
WHERE id = 1;

-- Delete data
DELETE FROM employees 
WHERE id = 1;
                        

Advanced SQL Concepts

  • Joins: Combine data from multiple tables
  • Subqueries: Nested queries within other queries
  • Indexes: Improve query performance
  • Views: Virtual tables based on query results
  • Stored Procedures: Reusable database functions
  • Triggers: Automatic actions on data changes

Popular SQL Database Systems

  • MySQL: Open-source, widely used for web applications
  • PostgreSQL: Advanced open-source database with rich features
  • Microsoft SQL Server: Enterprise database solution
  • Oracle Database: High-performance enterprise database
  • SQLite: Lightweight, embedded database