Beginner SQL Server interview questions
Q1 Beginner Aggregate Functions & GROUP BY
Short answer
Aggregate functions calculate a single summary value from a set of rows, such as counting how many rows exist, adding up a column, or finding the average, minimum, or maximum value.
Full answer with examples Q2 Beginner Always On Availability Groups
Short answer
An Always On Availability Group is a high availability feature that keeps a copy of one or more databases synchronized across multiple SQL Server instances, so if the main server fails, another server already holding an up to date copy can take over quickly, minimizing downtime…
Full answer with examples Q3 Beginner Backup & Recovery
Short answer
A full backup captures the entire database at a specific point in time, a differential backup captures only the changes made since the last full backup, and a transaction log backup captures all the transaction activity since the previous log backup, letting you restore your…
Full answer with examples Q4 Beginner Change Data Capture (CDC)
Short answer
Change Data Capture, often called CDC, automatically records insert, update, and delete activity on a table into a separate set of change tables, letting other systems or processes easily identify exactly what data has changed since the last time they checked, without needing to…
Full answer with examples Q5 Beginner Columnstore Indexes
Short answer
A regular index organizes data by row, while a columnstore index organizes and compresses data by column instead, which dramatically speeds up queries that scan and aggregate large amounts of data, such as reports that sum sales across millions of rows, since SQL Server only…
Full answer with examples Q6 Beginner Common Table Expressions (CTEs)
Short answer
A common table expression, defined using the WITH keyword, creates a temporary named result set that you can reference within a single query, making complex queries easier to read and organize compared to nesting several subqueries inside each other, especially when the same…
Full answer with examples Q7 Beginner Constraints (Primary Key, Foreign Key, Check & Unique)
Short answer
A primary key constraint uniquely identifies each row in a table, ensuring no two rows can have the same value in that column, and it also automatically prevents that column from containing NULL values, making it the reliable way other tables can reference a specific row.
Full answer with examples Q8 Beginner Cursors
Short answer
A cursor lets you process a query's results one row at a time, similar to how you might loop through a list in a programming language, but most developers avoid them because SQL Server is optimized for set based operations that work on entire groups of rows at once, and row by…
Full answer with examples Q9 Beginner Data Types & Schema Design
Short answer
INT is used for whole numbers like an id or a count, VARCHAR stores variable length text like names or descriptions, DECIMAL is used for precise numbers like currency where rounding errors matter, and DATETIME or DATE store date and time values, with the right choice depending…
Full answer with examples Q10 Beginner Deadlocks
Short answer
A deadlock happens when two or more transactions each hold a lock that the other transaction needs, creating a cycle where neither can move forward, so SQL Server must step in and end one of them so the other can continue.
Full answer with examples Q11 Beginner Dynamic Data Masking
Short answer
Dynamic data masking automatically hides sensitive information, like a full credit card number or an email address, from users who query a table but do not have special permission to see the unmasked value, without actually changing the real data stored in the database…
Full answer with examples Q12 Beginner Dynamic SQL
Short answer
Dynamic SQL means building a SQL statement as a text string at runtime and then executing it, which is useful when parts of your query, such as the table name or the columns being sorted by, are not known ahead of time and depend on some condition or user input determined while…
Full answer with examples Q13 Beginner Error Handling with TRY CATCH
Short answer
A TRY CATCH block lets you run a piece of SQL code inside the TRY section, and if any error occurs during its execution, control immediately jumps to the CATCH section instead of stopping the entire batch abruptly, letting you handle the error gracefully, such as logging it or…
Full answer with examples Q14 Beginner Full Text Search
Short answer
Full text search is a specialized indexing feature designed for efficiently searching large amounts of text, letting you find whole words or phrases quickly even in very large tables, while a regular LIKE search with wildcards has to scan through the text character by character…
Full answer with examples Q15 Beginner Hash Indexes & Hash Join Operations
Short answer
A hash join works by building a temporary hash table in memory from the smaller of the two input sets, based on the join column, and then scanning the larger input, checking each row against that hash table to quickly find matches, which works well when joining large, unsorted…
Full answer with examples Q16 Beginner Indexes
Short answer
An index creates a separate, organized structure that lets SQL Server quickly locate specific rows in a table without scanning every single row, similar to how the index at the back of a book lets you jump directly to a topic instead of reading every page to find it.
Full answer with examples Q17 Beginner In-Memory OLTP (Memory-Optimized Tables)
Short answer
In-Memory OLTP lets you create memory optimized tables that are held entirely in memory rather than on disk, using a different internal engine specifically designed for extremely fast data access, which can dramatically improve performance for workloads with very high numbers of…
Full answer with examples Q18 Beginner Isolation & Locking
Short answer
A lock is a mechanism SQL Server uses to control concurrent access to data, temporarily preventing other transactions from making conflicting changes to the same data at the same time, which protects the consistency and accuracy of your data when multiple users or processes are…
Full answer with examples Q19 Beginner Joins
Short answer
An INNER JOIN combines rows from two tables based on a matching condition, returning only the rows where a match is found in both tables, meaning any row without a corresponding match in the other table is simply left out of the results entirely.
Full answer with examples Q20 Beginner JSON Support in SQL Server
Short answer
SQL Server stores JSON as regular text in an NVARCHAR column, but provides special built-in functions that let you parse and query values from within that JSON text directly in your SQL statements, without needing a separate dedicated JSON data type or an external application to…
Full answer with examples Q21 Beginner Linked Servers
Short answer
A linked server lets your SQL Server instance connect to and query data from another database server, whether it is another SQL Server instance or a different type of database entirely, allowing you to write queries that combine data from multiple separate database servers as if…
Full answer with examples Q22 Beginner Merge Statement (Upsert)
Short answer
The MERGE statement lets you compare a source set of data against a target table and, in a single statement, insert new rows that do not yet exist, update existing rows that have changed, and optionally delete rows that no longer appear in the source, which is why it is commonly…
Full answer with examples Q23 Beginner Normalization
Short answer
Database normalization is the process of organizing tables and columns to reduce data duplication and improve data integrity, typically by breaking down a large table into smaller, related tables, which helps prevent inconsistencies that can occur when the same piece of…
Full answer with examples Q24 Beginner Partitioning
Short answer
Table partitioning splits a very large table into smaller, more manageable physical pieces called partitions, typically based on a range of values like a date column, while the table still appears as a single logical table to anyone querying it, making it easier to manage and…
Full answer with examples Q25 Beginner Pivoting & Unpivoting Data
Short answer
Pivoting transforms data from a row based format into a column based format, taking distinct values from one column and turning them into separate column headers, which is commonly used to build summary reports, such as showing monthly sales totals as separate columns instead of…
Full answer with examples Q26 Beginner Query Optimization & Plans
Short answer
An execution plan shows exactly how SQL Server intends to carry out a query, including which indexes it plans to use, how it will join tables together, and in what order operations will happen, giving you visibility into the actual strategy behind a query rather than just seeing…
Full answer with examples Q27 Beginner Query Store
Short answer
Query Store is a built-in feature that automatically captures a history of queries, their execution plans, and detailed runtime statistics like duration and resource usage over time, giving you a persistent record you can analyze later without needing to have already been…
Full answer with examples Q28 Beginner Replication
Short answer
Replication is a set of technologies that automatically copies and synchronizes data from one database, called the publisher, to one or more other databases, called subscribers, letting you distribute data to multiple locations for purposes like reporting, offloading read…
Full answer with examples Q29 Beginner SQL Server Agent & Job Scheduling
Short answer
SQL Server Agent is a background service that runs and manages scheduled jobs, such as regular database backups, index maintenance, data synchronization tasks, and custom scripts, letting administrators automate routine work so it runs reliably on a defined schedule without…
Full answer with examples Q30 Beginner SQL Server Architecture & Editions
Short answer
The database engine handles storing, processing, and securing data, the SQL Server Agent automates scheduled tasks, SQL Server Analysis Services supports business intelligence and data analysis, and SQL Server Integration Services handles moving and transforming data between…
Full answer with examples Q31 Beginner SQL Server Profiler & Extended Events
Short answer
SQL Server Profiler is a graphical tool that captures a detailed trace of events happening on a SQL Server instance, such as every query executed, how long each one took, and any errors encountered, historically used by developers and administrators to diagnose performance…
Full answer with examples Q32 Beginner SQL Server Security & Permissions
Short answer
A login is created at the server level and controls whether someone can connect to the SQL Server instance at all, while a database user exists within a specific database and is mapped to a login, controlling what that person is actually allowed to do once connected to that…
Full answer with examples Q33 Beginner Stored Procedures & Functions
Short answer
A stored procedure is a saved, reusable collection of SQL statements stored directly in the database, offering benefits like improved performance through plan reuse, better security since users can be granted permission to execute a procedure without direct table access, and…
Full answer with examples Q34 Beginner Subqueries
Short answer
A subquery is a query nested inside another query, often used within a WHERE clause to filter results based on the outcome of that inner query, within a SELECT list to calculate a related value, or within a FROM clause to treat its result as if it were a temporary table for the…
Full answer with examples Q35 Beginner Temporary Tables & Table Variables
Short answer
A local temporary table, created with a name starting with a single pound sign, is automatically dropped when the session that created it ends, and is only visible to that specific session, making it useful for storing intermediate results during a complex process without…
Full answer with examples Q36 Beginner Transactions & ACID
Short answer
A transaction groups one or more SQL statements together so they are treated as a single unit of work, meaning either all of the statements succeed together and their changes are saved, or if something goes wrong, all of the changes are undone together, protecting your data from…
Full answer with examples Q37 Beginner Transparent Data Encryption
Short answer
Transparent Data Encryption, often called TDE, encrypts an entire database's data and log files at rest on disk, protecting against the scenario where someone gains physical access to the actual database files or backup files and tries to read them directly, without requiring…
Full answer with examples Q38 Beginner Triggers
Short answer
A trigger is a special kind of stored procedure that automatically runs in response to a specific event, such as an INSERT, UPDATE, or DELETE happening on a table, or certain data definition events like creating a new table, letting you automatically enforce rules or perform…
Full answer with examples Q39 Beginner T-SQL Fundamentals & Syntax
Short answer
T-SQL, short for Transact-SQL, is Microsoft's extension of standard SQL used specifically in SQL Server, adding extra features beyond the standard SQL language, such as procedural programming constructs like variables, loops, and error handling, that let you write more powerful…
Full answer with examples Q40 Beginner User Defined Functions
Short answer
A user defined function lets you package a piece of reusable logic, such as a calculation or a formatting routine, into a single named object that you can call from many different queries, avoiding the need to repeat and maintain the same complex logic in multiple places…
Full answer with examples Q41 Beginner Views
Short answer
A view is a saved, named query that you can treat like a virtual table, letting you simplify complex queries by hiding their underlying complexity behind a simple name, restrict which columns or rows users can see for security purposes, and provide a consistent, reusable way to…
Full answer with examples Q42 Beginner Window Functions
Short answer
A window function performs a calculation across a set of related rows, similar to an aggregate function, but unlike GROUP BY, it does not collapse those rows into a single summarized result, instead returning a value for every individual row while still having access to…
Full answer with examples Q43 Beginner XML Data Type & Querying
Short answer
The XML data type stores XML documents in a way that SQL Server understands their structure, letting you validate them against a schema, query specific elements and attributes efficiently, and modify parts of the document, capabilities that would not be available if you simply…
Full answer with examples Q44 Beginner Aggregate Functions & GROUP BY
Short answer
GROUP BY splits your rows into separate groups based on the values in one or more columns, and then any aggregate function in your query calculates its result separately for each of those groups instead of for the entire table at once, letting you summarize data by category.
Full answer with examples Q45 Beginner Always On Availability Groups
Short answer
The primary replica is the active database that handles all the read and write operations from your applications, while secondary replicas hold a continuously updated copy of that data and can optionally be used for read only reporting queries, backups, or as a standby ready to…
Full answer with examples Q46 Beginner Backup & Recovery
Short answer
You use the RESTORE DATABASE statement, specifying the database name and the location of the backup file, and SQL Server will recreate the database exactly as it existed at the moment that full backup was taken, which is the starting point for any more complex restore involving…
Full answer with examples Q47 Beginner Columnstore Indexes
Short answer
A clustered columnstore index replaces the entire table's underlying storage with columnstore format and is typically used for large fact tables in a data warehouse, while a nonclustered columnstore index is added alongside an existing rowstore table, allowing the table to still…
Full answer with examples Q48 Beginner Common Table Expressions (CTEs)
Short answer
You separate multiple CTE definitions with a comma after the WITH keyword, and each subsequent CTE can even reference the ones defined before it, letting you build up a series of clearly named, logical steps that eventually feed into your final SELECT statement.
Full answer with examples Q49 Beginner Constraints (Primary Key, Foreign Key, Check & Unique)
Short answer
A foreign key constraint links a column in one table to the primary key of another table, ensuring that any value entered in that column must already exist in the referenced table, which prevents situations like an order being created for a customer id that does not actually…
Full answer with examples