Sharpen your grasp of key SQL concepts, command categories, and interview-ready syntax with this 15-question quiz designed for aspiring data engineers and SQL beginners. Tackle basic SQL classification, command usage, and simple query logic to boost your interview confidence.
Which SQL category is primarily used to define the structure of database tables?
Explanation: DDL (Data Definition Language) commands such as CREATE, ALTER, and DROP are used to define and modify the structure of database tables. DML is used for manipulating data, DQL for querying, and TCL for managing transactions, but only DDL changes the blueprint of the database.
Which SQL command is categorized under DQL (Data Query Language) and is used to retrieve data from a table?
Explanation: SELECT is the only major DQL command and is used to fetch data from tables. INSERT is a DML command for adding data, ALTER is a DDL command for modifying table structure, and COMMIT is a TCL command for transaction control.
If you want to modify data already stored in a table, which category of SQL commands should you use?
Explanation: DML (Data Manipulation Language) commands like UPDATE and DELETE allow you to modify or remove data within tables. DDL deals with table structure, TCL with transactions, and HTML is not related to SQL at all.
Which SQL command ensures that all changes made during a transaction are saved permanently?
Explanation: COMMIT finalizes all changes in a transaction, making them permanent. ROLLBACK undoes changes, TRUNCATE removes all rows from a table but is not a transaction command, and SELECT merely queries data.
How would you create a table called Students with columns for roll number, first name, and last name, where last name cannot be empty?
Explanation: The CREATE TABLE command defines a new table with specified columns and constraints. INSERT adds data, SELECT is for querying, and DELETE removes rows. Only CREATE TABLE matches the described requirement directly.
Why is a primary key used in SQL table definitions?
Explanation: A primary key ensures each row in a table is unique. It does not allow duplicates, isn't for storing all data, and isn't limited to only text data. Its core function is unique row identification.
Which command would you use to add a new column to an existing table?
Explanation: ALTER TABLE allows you to add, remove, or modify columns in an existing table. SELECT INTO copies data, COMMIT applies transaction changes, and ROLLBACK undoes transactions; none modifies table structure.
What SQL command will remove all rows from a table but keep its structure intact for future use?
Explanation: TRUNCATE deletes all records from a table but leaves the table definition for reuse. DROP removes the entire table structure, ALTER changes metadata, and ROLLUP is used for grouping, not deleting.
If you want to add a new student named 'Jane Doe' with roll number 5 to the Students table, which SQL command would be correct?
Explanation: INSERT INTO is used for adding new rows. SELECT only fetches records, COMMIT finalizes transactions, and ALTER is structural and not for adding data rows. Only the INSERT statement fits the requirement.
Which SQL query would select only the first name column from the Students table?
Explanation: SELECT fname FROM Students; is the correct syntax for selecting just the fname column. The other options are either syntactically incorrect or reverse the column and table placement.
What does the NOT NULL constraint ensure when defining a column in a table?
Explanation: NOT NULL ensures that every row has a value for the column, prohibiting empty fields. It does not enforce uniqueness or numeric-only entries, nor does it block SELECT statements from using the column.
If you mistakenly delete all records from a table but want to undo this action before finalizing, which command would you use?
Explanation: ROLLBACK reverts all changes made during the current transaction, undoing deletes and updates before a COMMIT occurs. DROP removes table structures, ALTER makes structural changes, and INSERT adds data but cannot undo deletions.
What does adding a UNIQUE constraint to a column enforce?
Explanation: A UNIQUE constraint guarantees all values in a column are distinct. It is not limited to text data, does not require the column to be a primary key, and does not specify NULL requirements.
Which command allows you to change an existing student's last name to 'Smith' in the Students table?
Explanation: UPDATE is used for modifying existing records. The correct syntax requires specifying which row(s) to update with WHERE. The other options misuse SQL keywords or describe incorrect operations for this scenario.
How would you remove only students named 'John' from the Students table?
Explanation: DELETE FROM Students WHERE fname = 'John'; removes specific rows with fname 'John'. DROP deletes entire tables, REMOVE is not a valid command in SQL, and ALTER changes table structures, not data.
What will the command SELECT * FROM Students; do?
Explanation: SELECT * FROM Students; shows all data in the table with all columns. It does not delete, create tables, or alter the table's columns. The asterisk is a wildcard to select every column for every row.