| Q | A |
|---|---|
| First appeared | 1974 |
| Paradigm | Declarative |
| Family | Query language |
| Typing discipline | Static, strong |
| Designed by | Donald D. Chamberlin, Raymond F. Boyce |
Database creation:
CREATE DATABASE mydatabase;Table creation:
CREATE TABLE users (
id INT PRIMARY KEY,
username VARCHAR(50),
email VARCHAR(100)
);Data Insertion:
INSERT INTO users (id, username, email)
VALUES (1, 'john_doe', '[email protected]');Data Querying:
SELECT * FROM users;Data Filtering:
SELECT * FROM users WHERE username = 'john_doe';Data Sorting and Limiting:
SELECT * FROM users ORDER BY username ASC LIMIT 10;Data Aggregation:
SELECT COUNT(*) FROM users; # Use aggregate functions like COUNT, SUM, AVG, MIN, and MAX for data analysisData Updating:
UPDATE users SET email = '[email protected]' WHERE id = 1;Data Deletion:
DELETE FROM users WHERE id = 1;Table Joining (used to combine rows from two or more tables based on a related column):
SELECT users.username, orders.order_id
FROM users
INNER JOIN orders ON users.id = orders.user_id;Table Editing:
ALTER TABLE table_name ADD column_name datatype;Table Deletion:
DROP TABLE table_name;List Databases:
SHOW DATABASES; # Displays a list of all the available databases
SHOW SCHEMAS; # an alternate for the SHOW DATABASES statementUse Database:
USE database_name; # Specifies which database to useList Tables:
SHOW TABLES; # Displays a list of tables in the current database