Explore tens of thousands of sets crafted by our community.
Basic SQL Commands
15
Flashcards
0/15
ALTER TABLE
Changes the structure of an existing table. Example usage: ALTER TABLE users ADD COLUMN birthday DATE;
DELETE
Removes records from a table. Example usage: DELETE FROM users WHERE user_id=1;
UNION
Combines the result sets of two or more SELECT statements. Example usage: SELECT username FROM users UNION SELECT name FROM customers;
CREATE TABLE
Creates a new table in the database. Example usage: CREATE TABLE users (user_id INT PRIMARY KEY, username VARCHAR(50), email VARCHAR(50));
INSERT INTO
Adds new records to a table. Example usage: INSERT INTO users (username, email) VALUES ('newuser', 'newuser@example.com');
HAVING
Adds a condition to filter groups made by GROUP BY. Example usage: SELECT COUNT(user_id), country FROM users GROUP BY country HAVING COUNT(user_id) > 10;
SELECT
Retrieves data from a database. Example usage: SELECT * FROM users;
GROUP BY
Arranges identical data into groups. Example usage: SELECT COUNT(user_id), country FROM users GROUP BY country;
UPDATE
Modifies existing records in a table. Example usage: UPDATE users SET email='newemail@example.com' WHERE user_id=1;
TRUNCATE TABLE
Deletes the data inside a table, but not the table itself. Example usage: TRUNCATE TABLE users;
ORDER BY
Sorts the result set of a query. Example usage: SELECT * FROM users ORDER BY username ASC;
JOIN
Combines rows from two or more tables. Example usage: SELECT * FROM orders JOIN customers ON orders.customer_id = customers.customer_id;
WHERE
Specifies a condition for filtering the records returned. Example usage: SELECT * FROM users WHERE username='john_doe';
INDEX
Creates a database index on one or more columns. Example usage: CREATE INDEX idx_username ON users (username);
DROP TABLE
Deletes a table and its data from the database. Example usage: DROP TABLE users;
© Hypatia.Tech. 2024 All rights reserved.