🧠 SQL Flashcards β€” CLI Edition

Use these to review quickly in a terminal-like format. Keep adding as you level up!


πŸ—‚οΈ  Question:
What is a database?

πŸ“¦  Answer:
A collection of related information that can be stored, queried, and managed.

πŸ—‚οΈ  Question:
What is SQL?

πŸ“¦  Answer:
A language used to manage and query relational databases (RDBMS).

πŸ—‚οΈ  Question:
What is NoSQL?

πŸ“¦  Answer:
A category of non-relational databases used for unstructured or semi-structured data.

πŸ—‚οΈ  Question:
What is the MySQL equivalent on Arch Linux?

πŸ“¦  Answer:
MariaDB is a drop-in replacement for MySQL on Arch Linux.

πŸ—‚οΈ  Question:
What is an RDBMS?

πŸ“¦  Answer:
Relational Database Management System β€” stores data in tables with relationships.

πŸ—‚οΈ  Question:
What is an NRDBMS?

πŸ“¦  Answer:
Non-relational Database Management System β€” stores data as documents, key-values, or graphs.

πŸ—‚οΈ  Question:
How do you create a new table?

πŸ“¦  Answer:
Use the CREATE TABLE statement with column names, types, and constraints.
Example:
CREATE TABLE users (id INT, name VARCHAR(100));

πŸ—‚οΈ  Question:
How do you see the structure of a table?

πŸ“¦  Answer:
Use: DESCRIBE table_name;

πŸ—‚οΈ  Question:
How do you add a column to an existing table?

πŸ“¦  Answer:
ALTER TABLE table_name ADD column_name datatype;

πŸ—‚οΈ  Question:
How do you modify a column's datatype?

πŸ“¦  Answer:
ALTER TABLE table_name MODIFY column_name new_datatype;

πŸ—‚οΈ  Question:
How do you delete a column from a table?

πŸ“¦  Answer:
ALTER TABLE table_name DROP COLUMN column_name;

πŸ—‚οΈ  Question:
How do you delete a table?

πŸ“¦  Answer:
DROP TABLE table_name;

πŸ—‚οΈ  Question:
How do you view all data from a table?

πŸ“¦  Answer:
SELECT * FROM table_name;

πŸ—‚οΈ  Question:
How do you insert data into a table?

πŸ“¦  Answer:
INSERT INTO table_name (col1, col2) VALUES (val1, val2);

πŸ—‚οΈ  Question:
What does NOT NULL do?

πŸ“¦  Answer:
Ensures a column cannot have NULL values.

πŸ—‚οΈ  Question:
What does UNIQUE do?

πŸ“¦  Answer:
Ensures all values in a column are unique.

πŸ—‚οΈ  Question:
What does DEFAULT do?

πŸ“¦  Answer:
Sets a default value for a column if no value is provided on insert.

πŸ—‚οΈ  Question:
What does AUTO_INCREMENT do?

πŸ“¦  Answer:
Automatically increases the value of a numeric column (usually a primary key) on each new insert.

πŸ—‚οΈ  Question:
What is a Primary Key?

πŸ“¦  Answer:
A column (or combination) that uniquely identifies each row in a table. Cannot be NULL or duplicated.

πŸ—‚οΈ  Question:
What is a Foreign Key?

πŸ“¦  Answer:
A column that refers to the Primary Key in another table to maintain relational integrity.

πŸ—‚οΈ  Question:
What is a Surrogate Key?

πŸ“¦  Answer:
An artificially generated key (like AUTO_INCREMENT or UUID) used to uniquely identify a record without business meaning.

πŸ—‚οΈ  Question:
What is a Composite Key?

πŸ“¦  Answer:
A Primary Key made up of multiple columns together to uniquely identify a row.

πŸ—‚οΈ  Question:
What is a Candidate Key?

πŸ“¦  Answer:
A column (or group) that could serve as a Primary Key β€” it's unique and non-null.

πŸ—‚οΈ  Question:
What is an Alternate Key?

πŸ“¦  Answer:
A Candidate Key that was not chosen as the Primary Key but is still unique and can identify rows.

πŸ—‚οΈ  Question:
What SQL statement is used to modify existing records in a table?

πŸ“¦  Answer:
UPDATE

πŸ—‚οΈ  Question:
What clause must you include with UPDATE to avoid changing all rows?

πŸ“¦  Answer:
WHERE clause

πŸ—‚οΈ  Question:
What happens if you run UPDATE students SET name = 'Tanvir'; without WHERE?

πŸ“¦  Answer:
It updates the name field for all rows in the students table.

πŸ—‚οΈ  Question:
What's the basic syntax of the UPDATE statement?

πŸ“¦  Answer:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

πŸ—‚οΈ  Question:
How do you remove records from a table in SQL?

πŸ“¦  Answer:
Using the DELETE statement

πŸ—‚οΈ  Question:
Write a SQL query to delete a student whose id is 5.

πŸ“¦  Answer:
DELETE FROM students
WHERE id = 5;

πŸ—‚οΈ  Question:
What happens if you run DELETE FROM students; without a WHERE clause?

πŸ“¦  Answer:
It deletes all rows from the students table.

πŸ—‚οΈ  Question:
Which SQL keyword starts a transaction to safely test updates or deletes?

πŸ“¦  Answer:
START TRANSACTION

πŸ—‚οΈ  Question:
What SQL command undoes changes made during a transaction?

πŸ“¦  Answer:
ROLLBACK

πŸ—‚οΈ  Question:
What’s the safest practice before running UPDATE or DELETE?

πŸ“¦  Answer:
Run a SELECT with the same WHERE clause to preview affected rows.

πŸ—‚οΈ  Question:
What does the wildcard % do in SQL?

πŸ“¦  Answer:
Matches zero or more characters in a LIKE pattern.
Example: 'A%' matches anything starting with A.

πŸ—‚οΈ  Question:
What’s the purpose of UNION in SQL?

πŸ“¦  Answer:
Combines result sets from two SELECT queries into one, removing duplicates.

πŸ—‚οΈ  Question:
How does an INNER JOIN work?

πŸ“¦  Answer:
Returns only the rows where there is a match in both joined tables.

πŸ—‚οΈ  Question:
What’s the difference between LEFT JOIN and RIGHT JOIN?

πŸ“¦  Answer:
LEFT JOIN returns all rows from the left table and matched rows from the right.
RIGHT JOIN does the opposite.

πŸ—‚οΈ  Question:
What does ON DELETE SET NULL do?

πŸ“¦  Answer:
When a referenced row is deleted, it sets the foreign key column to NULL.

πŸ—‚οΈ  Question:
What does ON DELETE CASCADE do?

πŸ“¦  Answer:
Automatically deletes rows in child table when the referenced row in parent table is deleted.

πŸ—‚οΈ  Question:
What’s a nested query (subquery)?

πŸ“¦  Answer:
A query within another query, often used to filter or compute dynamic conditions.

πŸ—‚οΈ  Question:
What does COUNT(*) do in SQL?

πŸ“¦  Answer:
Returns the total number of rows in a table.

πŸ—‚οΈ  Question:
How do you sort query results?

πŸ“¦  Answer:
Using ORDER BY clause: ORDER BY column ASC/DESC;

πŸ—‚οΈ  Question:
How do you limit the number of rows in a result?

πŸ“¦  Answer:
Using the LIMIT clause. Example: SELECT * FROM users LIMIT 10;

πŸ‘Ύ Keep these in mind when designing tables or answering DBMS interview questions.