Basic SELECT Query
Which SQL statement correctly retrieves all columns from the 'users' table?
- SELECT * FROM users;
- GET ALL FROM users;
- SELECT ALL users;
- PICK * FROM users;
- SELLECT * FROM users;
Inserting New Data
What is the correct SQL statement to add a new row with name 'John' and age 25 into the 'people' table (columns: name, age)?
- INSERT INTO people (name, age) VALUES ('John', 25);
- ADD (name='John', age=25) TO people;
- INSERT people name='John', age=25;
- INSERT INTO people VALUES ('John', 25);
- INSET INTO people (name, age) VALUES ('John', 25);
Updating Existing Records
Choose the proper SQL command to set the 'status' column to 'active' for a row in the 'accounts' table where id is 7.
- UPDATE accounts SET status = 'active' WHERE id = 7;
- CHANGE accounts SET status = 'active' WITH id = 7;
- MODIFY accounts status = 'active' WHERE id = 7;
- UPDATE accounts status = 'active' WHEN id = 7;
- UPDTAE accounts SET status = 'active' WHERE id = 7;
Deleting Records Safely
Which SQL statement correctly deletes the row from the 'orders' table where order_id is 102?
- DELETE FROM orders WHERE order_id = 102;
- REMOVE FROM orders WHERE order_id = 102;
- DELETE orders WHERE order_id = 102;
- DEL FROM orders WHERE order_id = 102;
- DELETE * FROM orders WHERE order_id = 102;
Replacing Existing Items
What happens if you use INSERT INTO on a table and supply a primary key value that already exists?
- The existing row is replaced with the new row data.
- An error occurs; duplicate primary keys are not allowed.
- The new row is appended with a warning.
- No action is taken; existing row remains.
- The table is truncated before insert.
Batch Writing in SQL
Which set of SQL operations can typically be executed in a single batch write statement to multiple tables?
- INSERT and DELETE
- UPDATE and INSERT
- DELETE and UPDATE
- READ and WRITE
- ALTER and SELECT
Understanding Conditional Updates
What does a conditional UPDATE statement do in SQL?
- Performs the update only if certain conditions about the data are met.
- Updates all records without checking any condition.
- Deletes the record if the condition fails.
- Creates a new record if the condition is true.
- Ignores records that match the condition.
Querying by Composite Key
If a table uses a composite primary key (user_id, date), what must you provide to update a single row?
- Both user_id and date values
- Only the user_id value
- Any one of the primary key columns
- None of the key values
- Just the table name
Atomic Counters
What does an atomic counter operation do in an UPDATE statement in SQL?
- Increments or decrements a numeric column in a row atomically
- Deletes a numeric column if it is zero
- Resets the counter to the initial value
- Splits the row into two rows
- Ignores all numeric changes
Efficient Updating vs. Delete-Insert
For changing a single column value in a large table, which operation is generally more efficient?
- UPDATE command on the row
- DELETE the row and then INSERT it with new value
- Drop the table and create a new one
- CREATE a duplicate table and copy data
- Run SELECT followed by REPLACE