Microsoft SQL Server 2022 Intermediate-Level Questions
1. What are the main features introduced in SQL Server 2022?
SQL Server 2022 introduces several new features, including Azure Synapse Link integration, Ledger for SQL Server, containing Availability Groups, enhanced Query Store, and improvements in security, performance, and availability.
2. Explain the difference between clustered and non-clustered indexes in SQL Server.
A clustered index sorts and stores the data rows in the table or view based on the key values. Each table can have only one clustered index. A non-clustered index, on the other hand, does not alter the way data is stored but creates a separate object within the table that points back to the original row, allowing for more than one non-clustered index per table.
3. What is a SQL Server Agent?
SQL Server Agent is a Microsoft Windows service that executes scheduled administrative tasks, which are called jobs in SQL Server. It can manage job scheduling, alert system, and operators for notifying event responses.
4. Can you explain what a transaction is in SQL Server?
A transaction in SQL Server is a single unit of work. If a transaction is successful, all of the data modifications made during the transaction are committed and become a permanent part of the database. If a transaction encounters errors and must be canceled or rolled back, then all of the data modifications are erased.
5. What are the ACID properties?
ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure that transactions are processed reliably: Atomicity guarantees that all operations within the work unit are completed successfully; Consistency ensures that the database properly changes states upon a successfully committed transaction; Isolation ensures that transactions are securely and independently processed simultaneously without interference; Durability guarantees that once a transaction is committed, it will remain so, even in the event of a power loss, crash, or error.
6. What is SQL Server Management Studio (SSMS)?
SQL Server Management Studio (SSMS) is an integrated environment for managing any SQL infrastructure, from SQL Server to Azure SQL Database. SSMS provides tools to configure, monitor, and administer instances of SQL, as well as to deploy, monitor, and upgrade the data-tier components used by your applications, and build queries and scripts.
7. How do you back up a SQL Server database?
To back up a SQL Server database, you can use the BACKUP DATABASE command, specifying the name of the database to back up and the location to store the backup file.
8. What is a SQL Server trigger?
A trigger in SQL Server is a special kind of stored procedure that automatically runs when certain events occur in the database table, such as insert, update, or delete operations.
9. Can you explain what a deadlock is and how SQL Server handles deadlocks?
A deadlock occurs when two or more sessions are waiting for each other to release locks, in a circular chain, so that they can proceed with their transaction. SQL Server detects deadlocks automatically and resolves them by choosing one process as a deadlock victim and rolling back its transaction, allowing other transactions to proceed.
10. What is the purpose of the UPDATE_STATISTICS command?
The UPDATE_STATISTICS command updates the statistics used by the query optimizer to determine the most efficient way to execute a query. These statistics provide information about the distribution of values in an index or table column and are crucial for query performance.
11. Describe what a View is in SQL Server.
A view in SQL Server is a virtual table based on the result-set of an SQL statement. It contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
12. What is a stored procedure in SQL Server?
A stored procedure is a prepared SQL code that you can save and reuse. Instead of writing the same code over and over again, you can create a stored procedure, and call it to execute the SQL code contained within it.
13. Explain what SQL Server Integration Services (SSIS) is.
SQL Server Integration Services (SSIS) is a platform for building enterprise-level data integration and data transformations solutions. You can use SSIS to solve complex business problems by copying or downloading files, loading data warehouses, cleansing and mining data, and managing SQL Server objects and data.
14. What are the recovery models available in SQL Server?
SQL Server offers three recovery models: Simple, Full, and Bulk-Logged. Each model dictates how transaction logs are maintained and impacts how you can restore and recover data.
15. What is database normalization?
Database normalization is the process of organizing the fields and tables of a database to minimize redundancy and dependency. Normalization involves dividing large tables into smaller tables and defining relationships between them to increase the coherence of data.
16. How do you perform a point-in-time recovery in SQL Server?
A point-in-time recovery involves restoring a SQL Server database to a specific point in time. This is achieved by restoring the full backup, the differential backup, and the transaction log backups up to the desired point of time.
17. What is the purpose of the NOLOCK hint?
The NOLOCK hint allows SQL Server to ignore locks, providing a way to read data without being blocked by other transactions. It's used to increase performance in scenarios where real-time accuracy of data is not critical.
18. How can you improve the performance of a SQL Server database?
Performance can be improved by indexing, query optimization, database normalization, updating statistics, avoiding unnecessary cursors, and configuring database files and filegroups optimally.
19. What are the differences between DELETE and TRUNCATE commands?
DELETE removes rows from a table based on the WHERE condition and can be rolled back. TRUNCATE removes all rows from a table without logging the individual row deletions, thus it's faster but cannot be rolled back.
20. What is SQL Server Reporting Services (SSRS)?
SQL Server Reporting Services (SSRS) is a server-based report generating software system that enables users to create and manage a wide range of reports. It supports various report delivery options and interactive reports.