SQL Server Quiz Questions And Answers

Reviewed by Samy Boulos
Samy Boulos, MSc (Computer Science) |
Data Engineer
Review Board Member
Samy Boulos is an experienced Technology Consultant with a diverse 25-year career encompassing software development, data migration, integration, technical support, and cloud computing. He leverages his technical expertise and strategic mindset to solve complex IT challenges, delivering efficient and innovative solutions to clients.
, MSc (Computer Science)
By Telliant
T
Telliant
Community Contributor
Quizzes Created: 3 | Total Attempts: 13,963
| Attempts: 8,264 | Questions: 25
Please wait...
Question 1 / 25
0 %
0/100
Score 0/100
1. What is the default join type used when only the keyword JOIN is specified?

Explanation

When only the keyword JOIN is specified without any other specific join type, the default join type used is INNER JOIN. This means that only the matching rows between the two tables will be included in the result set, excluding any non-matching rows.

Submit
Please wait...
About This Quiz
SQL Server Quiz Questions And Answers - Quiz

Have you ever worked on an SQL server? What do you know about this database system? We have here this "SQL server quiz questions and answers" for you.... see moreMicrosoft SQL Server is a DBMS developed by Microsoft for storing and retrieving data. In this SQL quiz, we will test your knowledge and understanding of various SQL concepts and terminologies. You can easily crack this quiz if you consider yourself a true database administrator. Want to check your memory for the same? Take this test, then! see less

2. Assuming UserProfile is a table with PKUserId int, Profession Varchar(50)columns. What is the result of the below query: SELECT PKUserId,Profession  FROM UserProfile WHERE Profession = 'Engineer' AND (PKUserId > 12 OR PKUserId = 1)

Explanation

The query selects rows from the UserProfile table where the Profession column is 'Engineer' and the PKUserId is either greater than 12 or equal to 1. Therefore, the result of the query will display users with the Profession as 'engineer' and the PKUserId greater than 12, as well as the user with a PKUserId of 1.

Submit
3. What is the result of the below query: SELECT SUBSTRING('DOTNET', 1, 3) AS 'Substring'

Explanation

The result of the given query is "DOT". The SUBSTRING function is used to extract a substring from a given string. In this case, the string "DOTNET" is being passed as the first argument, and the second and third arguments specify the starting position and length of the substring to be extracted. Since the starting position is 1 and the length is 3, the substring "DOT" is returned as the result.

Submit
4. Which of the following queries returns the users whose username starts with any of the characters between v to z?

Explanation

The correct answer is "SELECT PKUserId, UserName FROM UserProfile WHERE (UserName LIKE '[v-z]%')". This query uses the LIKE operator with a character range [v-z] to match usernames that start with any character between v and z. The % wildcard is used to match any number of characters after the specified range.

Submit
5. Assuming UserProfile is a table containing a column Proession that accepts a NULL value. What is the result of the query below? SET ANSI_NULLS OFF SELECT Profession FROM UserProfile WHERE (Profession <> NULL).

Explanation

The correct answer is "Returns all Professions which do not have null values." This is because the query is using the operator, which is the "not equal to" operator in SQL. When comparing a value to NULL using this operator, the result will be either true or false, but not NULL. Therefore, the query will return all rows where the Profession column is not NULL.

Submit
6. The SELECT statement must include which of the following clause:

Explanation

A basic SQL SELECT statement must include:

SELECT clause → to specify the columns you want to retrieve

FROM clause → to specify the table from which to retrieve the data

Example:

sql

SELECT name, age FROM students;

Without both SELECT and FROM, the statement is incomplete (except in special cases like using SELECT 1, which does not pull from a table). But in standard usage when accessing data, both clauses are required.

Therefore, the correct answer is:

Both A and B

Submit
7. Which of the following is true about the SERIALIZABLE isolation level ?

Explanation

The correct answer is "All of the above." The SERIALIZABLE isolation level in database transactions protects against phantom reads, which occur when a transaction reads rows that do not exist yet due to concurrent modifications. Additionally, this isolation level causes the highest level of contention, as it locks the entire table for the duration of the transaction, preventing other transactions from accessing it concurrently. It also causes the highest level of blocking, as transactions may have to wait for locks to be released before proceeding. Therefore, all the statements provided are true for the SERIALIZABLE isolation level.

Submit
8. Which of the following is true?

Explanation

All of the above is the correct answer because both statements are true. BUILT-IN functions in SQL Server are indeed Nondeterministic, meaning that their output can vary for the same input. On the other hand, the ISNULL function in SQL Server is Deterministic, meaning that its output is always the same for a given input. Therefore, both statements are correct and the correct answer is "All of the above."

Submit
9. How many transactions at a time can obtain an update lock on a resource?

Explanation

Only one transaction at a time can obtain an update lock on a resource. This means that while one transaction has acquired the update lock, other transactions will have to wait until the lock is released before they can obtain it. This ensures that only one transaction can make changes to the resource at any given time, preventing conflicts and ensuring data integrity.

Submit
10. Assuming Emp table with EmpId(int), Name(varchar(100)),HireDate(DateTime),Designation(varchar(20)) columns and Audit table with currentDate(DateTime), EmpId columns. What is the result of the following query: INSERT INTO Emp(Name,HireDate,Designation) OUTPUT getdate(), inserted.EmpId INTO Audit VALUES ('Robot','1/1/2011','Executive');

Explanation

The given query will insert a new row into the Emp table with the values 'Robot', '1/1/2011', and 'Executive' for the Name, HireDate, and Designation columns respectively. Additionally, it will also add a corresponding row into the Audit table with the current date and time and the EmpId for the new employee. Therefore, the correct answer is that it adds a new row to the Emp table and also adds a corresponding row with the current date and time and the EmpId for the new employee into the Audit table.

Submit
11. Which of the following options can be used for viewing lock status within your computer running SQL Server?

Explanation

The correct answer is "All of the above." This is because all of the options mentioned can be used for viewing lock status within a computer running SQL Server. SQL Profiler can capture lock and blocking information, the System Monitor can capture statistics on lock wait times, locks per second, and more, the Activity Monitor in SSMS can provide information on blocking processes, and the sys.dm_tran_locks dynamic management view can gather information on locks held by transactions.

Submit
12. Which of the following is true?

Explanation

Both A and C are true. A) NULL values are ignored for all the aggregate functions, meaning that if there are any NULL values in the data being aggregated, they will not be included in the calculation of the aggregate function. C) When an aggregate function is included in the SELECT clause, all other expressions in the SELECT clause must either be aggregate functions or included in a GROUP BY clause. This is because the aggregate function is operating on a group of rows and the other expressions need to be either part of that group or also aggregated.

Submit
13. Which of the following is correct?

Explanation

The correct answer is "Only A and C." This means that both the DELETE statement and the TRUNCATE TABLE statement log information on each row deleted. Additionally, the TRUNCATE TABLE statement executes fast and requires fewer resources on the server.

Submit
14. What is the output of the below query: SELECT CHARINDEX('DOT%', 'DOTNET') AS 'CharIndex'

Explanation

The CHARINDEX function in SQL Server returns the starting position of a specified expression within a string. In this query, the expression 'DOT%' is being searched within the string 'DOTNET'. Since the expression is not found within the string, the function returns 0 as the output.

Submit
15. Assuming the following query is executed on 31st Dec 2011. What is the result of the below query? SELECT CONVERT(varchar(30), GETDATE(), 111) AS Expr1

Explanation

The query is using the GETDATE() function to get the current date and then converting it to a varchar format with the format code 111. The format code 111 represents the format "yyyy/MM/dd". Therefore, the result of the query will be the current date in the format "2011/12/31".

Submit
16. What is the result of the below query: SELECT PATINDEX('DOT%', 'DOTNET') AS 'Index'

Explanation

The PATINDEX function in SQL Server is used to find the starting position of a specified pattern (in this case, 'DOT%') within a given string ('DOTNET'). In this example, 'DOT%' matches the beginning of 'DOTNET,' so the function returns 1, which is the position where the pattern 'DOT%' starts within the string 'DOTNET.'

Submit
17. To rollback a portion of a transaction, We have to define ___.

Explanation

Savepoints are used to define points within a transaction where it can be rolled back to in case of any issues or errors. By using savepoints, we can undo a portion of a transaction without having to roll back the entire transaction. This allows for more flexibility and control over the transaction process. Checkpoints, on the other hand, are used for recovery purposes and do not specifically deal with rolling back a portion of a transaction. Transactions, while related to the concept of rollback, do not specifically define the points within a transaction where rollback can occur. Therefore, the correct answer is savepoints.

Submit
18. The _____ object is used to retrieve information about all active transactions on an instance.

Explanation

The correct answer is sys.dm_tran_active_transactions. This object is used to retrieve information about all active transactions on an instance. It provides details such as the transaction ID, transaction state, transaction type, and the time when the transaction was started. By querying this object, administrators can monitor and analyze the active transactions on the instance to identify any potential issues or bottlenecks.

Submit
19. By default, what type of index is created for a unique constraint?

Explanation

When a unique constraint is created by default, a non-clustered index is also created. A non-clustered index is a separate structure that contains a sorted list of the indexed column's values and a pointer to the actual data row. This allows for efficient searching and retrieval of data based on the indexed column, while still allowing the data to be physically stored in a different order.

Submit
20. Assuming UserProfile is a table containing a column Profession which accepts NULL value. What is the result of the below query?   SET ANSI_NULLS ON SELECT     Profession FROM         UserProfile WHERE     (Profession <>  NULL)

Explanation

The query is using the condition (Profession <> NULL) to filter the records. However, comparing a value to NULL using the <> operator will always result in a NULL value, not true or false. Therefore, the condition will not retrieve any records, even if the profession column contains values.

Submit
21.  If the following code was run on 31st Dec 2011, What is the result of the below query: SELECT DATEDIFF(YEAR, GETDATE(), '8/8/2003') AS 'Difference'

Explanation

The query is calculating the difference in years between the current date and the date '8/8/2003'. Since the current date is after '8/8/2003', the result will be negative. The result of -8 indicates that the current date is 8 years ahead of '8/8/2003'.

Submit
22. Assuming Emp, EmpCompress 2 tables with the same schema: EmpId(Int), Name(varchar(50)), DeptId(Int). If a company wants to move all rows for Employees working in the IT Department from the Employees table to the Employees Archive table. Which of the following queries can be used?

Explanation



The correct query deletes rows from the "Emp" table where the department is IT and inserts the deleted rows into the "EmpCompress" table. It utilizes the OUTPUT clause to capture the deleted rows and the JOIN clause to match records based on the department ID.
Submit
23. BEGIN TRANSACTION INSERT INTO DemoTable VALUES(5,'XYZ','DEMO'); BEGIN TRANSACTION UPDATE DemoTable SET Col3 = 'Test' WHERE TestID = 5; COMMIT TRANSACTION; ROLLBACK; What is the result of the above code execution?

Explanation

The correct answer is "All of the above." This is because the code begins a transaction on line 1, inserts a row into the DemoTable on line 2, begins another transaction on line 3, updates the Col3 value for the row with TestID = 5 on line 4, commits the transaction on line 5, and then rolls back the transaction on line 6. As a result, the data is rolled back to the transaction starting on line 1, meaning that the inserted row does not exist in the table. Therefore, all of the statements in the answer options are true.

Submit
24. Which of the following commands is used to retrieve information about the information contained in the current transaction log ?

Explanation

The correct answer is DBCC LOGGING statement. This command is used to retrieve information about the information contained in the current transaction log. It allows users to view the log records, including the log sequence number, transaction ID, operation type, and other relevant details. The DBCC LOGGING statement is specifically designed for managing and analyzing transaction logs in a database system.

Submit
25.   Which of the following is a best practice to reduce deadlock situations?

Explanation

Accessing resources in the same order whenever possible within transactions is a best practice to reduce deadlock situations. Deadlocks occur when two or more transactions are waiting for each other to release resources, resulting in a deadlock situation. By accessing resources in the same order, the likelihood of deadlocks is reduced because it ensures that transactions will not be waiting indefinitely for resources that are being held by other transactions. This practice helps to maintain a consistent order of resource access and prevents potential deadlocks from occurring.

Submit
View My Results
Samy Boulos |MSc (Computer Science) |
Data Engineer
Samy Boulos is an experienced Technology Consultant with a diverse 25-year career encompassing software development, data migration, integration, technical support, and cloud computing. He leverages his technical expertise and strategic mindset to solve complex IT challenges, delivering efficient and innovative solutions to clients.

Quiz Review Timeline (Updated): Jun 30, 2025 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Jun 30, 2025
    Quiz Edited by
    ProProfs Editorial Team

    Expert Reviewed by
    Samy Boulos
  • Feb 13, 2012
    Quiz Created by
    Telliant
Cancel
  • All
    All (25)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the default join type used when only the keyword JOIN is...
Assuming UserProfile is a table with PKUserId int, Profession...
What is the result of the below query: ...
Which of the following queries returns the users whose username starts...
Assuming UserProfile is a table containing a column Proession that...
The SELECT statement must include which of the following clause:
Which of the following is true about the SERIALIZABLE isolation level...
Which of the following is true?
How many transactions at a time can obtain an update lock on a...
Assuming Emp table with EmpId(int),...
Which of the following options can be used for viewing lock status...
Which of the following is true?
Which of the following is correct?
What is the output of the below query:...
Assuming the following query is executed on 31st Dec 2011. What is the...
What is the result of the below query: ...
To rollback a portion of a transaction, We have to define ___.
The _____ object is used to retrieve information about all active...
By default, what type of index is created for a unique constraint?
Assuming UserProfile is a table containing a column Profession which...
 If the following code was run on 31st Dec 2011, What is the...
Assuming Emp, EmpCompress 2 tables with the same schema: EmpId(Int),...
BEGIN TRANSACTION...
Which of the following commands is used to retrieve information about...
  Which of the following is a best practice to reduce...
Alert!

Advertisement