MCQs on Data Modification | SQL Server

Dive into SQL Server’s Data Modification techniques with 30 tailored MCQs on INSERT, UPDATE, DELETE statements, handling NULL values, bulk insert operations, and the basics of transactions for mastery.


INSERT, UPDATE, DELETE Statements

  1. What is the result of the following statement?sqlCopy codeINSERT INTO Employees (Name, Age) VALUES ('John Doe', 30); a) Adds a new row with Name “John Doe” and Age 30
    b) Updates the row with Name “John Doe”
    c) Deletes the row with Name “John Doe”
    d) Throws an error as the table is empty
  2. Which clause ensures only specific rows are updated in a table?
    a) WHERE
    b) HAVING
    c) GROUP BY
    d) SELECT
  3. What happens when you execute the following statement? DELETE FROM Orders; a) Deletes all rows in the Orders table
    b) Deletes the Orders table
    c) Deletes rows where the condition is true
    d) Throws an error
  4. Which keyword is used to modify existing records in a table?
    a) INSERT
    b) UPDATE
    c) DELETE
    d) SELECT
  5. What is mandatory when using the DELETE statement to avoid deleting all rows unintentionally?
    a) WHERE clause
    b) ORDER BY clause
    c) JOIN clause
    d) LIMIT clause

Understanding NULL Values

  1. What is the result of the following query if the “Address” field is NULL? SELECT Name FROM Customers WHERE Address = NULL; a) Returns all rows
    b) Returns no rows
    c) Returns rows with NULL in the Address field
    d) Throws an error
  2. Which operator is used to check for NULL values in SQL Server?
    a) IS NULL
    b) = NULL
    c) IN NULL
    d) NULL CHECK
  3. What will the following query return? SELECT ISNULL(NULL, 'No Address'); a) NULL
    b) ‘No Address’
    c) Throws an error
    d) An empty string
  4. If a column contains NULL values, what is the result of SUM(column_name)?
    a) NULL
    b) Ignores NULL values and sums the rest
    c) Throws an error
    d) Returns 0
  5. What happens when NULL values are compared using the equality operator (=)?
    a) Returns TRUE
    b) Returns FALSE
    c) Returns UNKNOWN
    d) Throws an error

Bulk Insert Operations

  1. Which statement is used to perform bulk data insertion in SQL Server?
    a) BULK INSERT
    b) MASS INSERT
    c) BULK LOAD
    d) INSERT BULK
  2. What does the “FIELDTERMINATOR” argument specify in the BULK INSERT statement?
    a) The character separating data fields in the file
    b) The line delimiter in the file
    c) The file path
    d) The maximum file size
  3. What happens if the file path provided in a BULK INSERT statement is invalid?
    a) No rows are inserted, and an error is thrown
    b) Partial rows are inserted
    c) Only the valid rows are inserted
    d) The file is created automatically
  4. Which option enables you to log errors during a BULK INSERT operation?
    a) ERRORFILE
    b) LOGFILE
    c) ERRORS LOG
    d) DEBUG LOG
  5. Which file format is NOT supported by the BULK INSERT statement in SQL Server?
    a) CSV
    b) TXT
    c) XML
    d) DAT

Introduction to Transactions

  1. What is the purpose of a transaction in SQL Server?
    a) To execute all operations as a single unit of work
    b) To automatically back up the database
    c) To create a new database user
    d) To optimize query performance
  2. Which command is used to explicitly begin a transaction?
    a) START TRANSACTION
    b) BEGIN TRANSACTION
    c) TRANSACTION START
    d) BEGIN WORK
  3. What happens if a transaction is not committed or rolled back?
    a) The changes remain in a pending state
    b) The changes are automatically committed
    c) The transaction is automatically rolled back
    d) Throws an error
  4. What is the role of the COMMIT statement in a transaction?
    a) It permanently saves the changes made during the transaction
    b) It cancels all changes made during the transaction
    c) It starts a new transaction
    d) It temporarily saves the changes
  5. When does a transaction rollback automatically?
    a) When an error occurs
    b) When the COMMIT statement is executed
    c) When the SAVEPOINT is reached
    d) When the transaction is idle for 5 minutes

Mixed Topics

  1. What happens when you execute an UPDATE statement without a WHERE clause?
    a) Updates all rows in the table
    b) Updates only the first row
    c) Throws an error
    d) Updates no rows
  2. Which keyword ensures atomicity when combining multiple SQL statements?
    a) TRANSACTION
    b) TRIGGER
    c) FUNCTION
    d) PROCEDURE
  3. What will be the output of the following statement? INSERT INTO Employees DEFAULT VALUES; a) Inserts a row with default values
    b) Inserts a row with NULL values
    c) Throws an error
    d) Inserts a row with zeroes
  4. Which clause is used to remove duplicate rows in a SELECT query?
    a) DISTINCT
    b) UNIQUE
    c) FILTER
    d) REMOVE
  5. What is the result of the following statement? BEGIN TRANSACTION UPDATE Products SET Price = Price * 0.9; ROLLBACK TRANSACTION; a) The prices remain unchanged
    b) The prices are updated
    c) The transaction is committed
    d) Throws an error
  6. Which isolation level is the default in SQL Server?
    a) READ COMMITTED
    b) READ UNCOMMITTED
    c) SERIALIZABLE
    d) REPEATABLE READ
  7. What does the SAVEPOINT statement allow you to do in a transaction?
    a) Create intermediate points for rollback
    b) Automatically commit the transaction
    c) Add a comment to the transaction
    d) End the transaction
  8. Which SQL command reverts all changes made during a transaction?
    a) ROLLBACK
    b) UNDO
    c) REVERT
    d) CANCEL
  9. What happens if a BULK INSERT operation violates a primary key constraint?
    a) The operation is stopped with an error
    b) The row is skipped, and the operation continues
    c) The operation completes successfully
    d) All rows are inserted except duplicates
  10. What is the difference between DELETE and TRUNCATE?
    a) DELETE can include a WHERE clause, TRUNCATE cannot
    b) TRUNCATE removes data and the table structure
    c) DELETE cannot use conditions
    d) TRUNCATE is slower than DELETE

Answer Key

QnoAnswer
1a) Adds a new row with Name “John Doe” and Age 30
2a) WHERE
3a) Deletes all rows in the Orders table
4b) UPDATE
5a) WHERE clause
6b) Returns no rows
7a) IS NULL
8b) ‘No Address’
9b) Ignores NULL values and sums the rest
10c) Returns UNKNOWN
11a) BULK INSERT
12a) The character separating data fields in the file
13a) No rows are inserted, and an error is thrown
14a) ERRORFILE
15c) XML
16a) To execute all operations as a single unit of work
17b) BEGIN TRANSACTION
18a) The changes remain in a pending state
19a) It permanently saves the changes made during the transaction
20a) When an error occurs
21a) Updates all rows in the table
22a) TRANSACTION
23a) Inserts a row with default values
24a) DISTINCT
25a) The prices remain unchanged
26a) READ COMMITTED
27a) Create intermediate points for rollback
28a) ROLLBACK
29a) The operation is stopped with an error
30a) DELETE can include a WHERE clause, TRUNCATE cannot

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top