SQL Server basics: understand instances, databases, and transactions
Microsoft SQL Server is a database management system that receives application requests to store, query, and change relational data. A client connects to an instance of the SQL Server Database Engine and submits work in Transact-SQL (T-SQL). Each database uses data files and a transaction log; explicit transactions group multiple changes into one unit of work. Understanding these layers helps distinguish the server, instance, database, and files—and clarifies what must be rolled back or recovered after an error. This guide follows Microsoft Learn documentation reviewed on 23 November 2026.
How do SQL Server, the Database Engine, and an instance differ?
SQL Server is a product name and a database platform. Its core Database Engine is a service that stores and processes data and applies security. Client tools and programs connect to an instance of this Engine and send Transact-SQL (T-SQL). T-SQL builds on SQL and adds SQL Server features for defining and changing data, variables, control flow, and error handling. What is SQL Server? · Database Engine overview
An instance is a SQL Server Database Engine environment that clients connect to. A host can run a default instance or named instances, and a client uses the instance plus network protocol and port details to connect. Once connected, it works with a database within that instance. Creating another database does not automatically create another server process or host. Installation, instance names, authentication, and network settings vary by deployment, so check the connection configuration for the environment you use. Connect to the Database Engine
SQL Server, Azure SQL Database, and Azure SQL Managed Instance use shared Database Engine technology, but they are distinct deployment products. Microsoft documents differences in T-SQL support across platforms. This guide focuses on an installed SQL Server Database Engine for its instance and file model; it does not cover all operational differences in Azure managed services or Fabric. Database Engine products and platforms
The names are related, but each layer has a different responsibility.
| Layer | Responsibility | Example |
|---|---|---|
| Client | Connects and exchanges T-SQL requests and results | SSMS, sqlcmd, application driver |
| Instance/Database Engine | Manages sessions and performs security, query processing, and transactions | Default or named instance |
| Database | Logically groups related objects and settings | dbo.Orders in the Sales database |
| Data file | Provides storage for tables, indexes, and other objects | Primary .mdf, optional .ndf |
| Transaction log | Preserves change records to support commit, rollback, and recovery | That database's .ldf log |
One instance can manage multiple databases, and a database can have one or more data files and log files. This hierarchy helps distinguish tasks such as “connect to an instance,” “select a database,” and “check data-file capacity.”
What do the data files and log do?
At minimum, a SQL Server database has a data file and a transaction log file. Data files hold database objects such as tables, indexes, stored procedures, and views. The transaction log records transactions and changes so the database can be recovered to a consistent state. .mdf, .ndf, and .ldf are commonly recommended extensions for primary data, secondary data, and log files; they are not the only rule that defines a file's role. Database files and filegroups · Transaction log architecture
The log is more than a change-history note. The Database Engine uses write-ahead logging (WAL): the related log record is written before a changed data page is written to disk. This ordering matters for crash recovery and transaction atomicity and durability. The log file has a different role from data files and must be managed according to recovery requirements. Do not delete or move it as if it were a disposable cleanup file. Log backups, recovery models, and log reuse are separate operational topics outside this introduction. The SQL Server transaction log · WAL explanation
How does a transaction group multiple changes?
A transaction treats several database operations as one logical unit. For example, fulfilling an order may require both reducing inventory and inserting an order row. Both changes should succeed together; otherwise the records can disagree. Use COMMIT TRANSACTION to confirm success or ROLLBACK TRANSACTION to undo changes after failure. Microsoft describes transactions with ACID properties: atomicity, consistency, isolation, and durability. Actual guarantees and performance can depend on isolation, delayed durability, and other configuration choices. Transactions and ACID · BEGIN TRANSACTION
The example below is a hypothetical inventory operation. It illustrates T-SQL and was not run or validated against a SQL Server instance.
SET XACT_ABORT ON;
BEGIN TRY
BEGIN TRANSACTION;
UPDATE dbo.Inventory
SET Quantity = Quantity - 1
WHERE ProductId = 42 AND Quantity > 0;
IF @@ROWCOUNT <> 1
THROW 50001, 'Product missing or stock insufficient.', 1;
INSERT INTO dbo.Orders (ProductId, Quantity)
VALUES (42, 1);
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0
ROLLBACK TRANSACTION;
THROW;
END CATCH;@@ROWCOUNT checks how many rows the immediately preceding UPDATE changed. The order is added only if one matching inventory row was updated. SET XACT_ABORT ON specifies that a run-time error rolls back the current transaction, while TRY...CATCH and XACT_STATE() help handle an error and determine whether a transaction remains active. THROW passes the error back to the caller. A real application must define the tables and keys and handle its business rules, duplicate orders, retries, and user-facing response. The snippet does not provide those rules by itself. SET XACT_ABORT · TRY...CATCH and XACT_STATE
Long-running transactions hold locks and other resources for longer and can affect other sessions and log management. Avoid keeping a database transaction open while waiting for an external API or user input. A common pattern is to do the required database changes in a short transaction and commit, while choosing boundaries and isolation to match the application's consistency requirements. Locking and row versioning guide · Effects of long-running transactions
Where can SQL Server be deployed and how do clients connect?
SQL Server can be installed on Windows or Linux and deployed in Linux containers or virtual machines. Azure SQL products share underlying Engine technology but differ in management responsibilities and supported features. Do not infer that operating-system access, file management, or instance settings are identical just because two products use T-SQL. Identify the deployment product and exact version, then use its platform documentation and edition feature matrix. Deployment options and version scope · Platform feature differences
Clients connect by specifying an instance. Tools Microsoft documents include SQL Server Management Studio (SSMS), the MSSQL extension for Visual Studio Code, and sqlcmd. The actual connection also depends on authentication, network protocol, firewall, and port configuration. A successful local development connection does not verify those settings in production. Connecting to the Database Engine
What should you check when getting started?
An introductory sequence is:
Identify whether you use installed SQL Server or a managed service such as Azure SQL.
Connect with the exact instance and authentication method, then confirm the database you intend to use.
Treat data files and the transaction log as separate components; do not delete or move files manually.
Use an explicit transaction for related changes, commit only when all steps succeed, and roll back on the error path.
Before storing important data, agree on backup and restore, permissions, isolation, log capacity, and monitoring with the operations owner.
Success is more than “the query ran.” Confirm that you connected to the intended database, that the before-and-after rows and constraints match the business rule, and that an error leaves no partial change. Validate with limited test data rather than experimenting on production data. This article did not connect to an instance or run the example.
Scope and sources
This introduction is based on Microsoft Learn documentation reviewed on 23 November 2026 about SQL Server concepts, Engine connections, database files, transaction logs, and error handling. Installation procedures, version support lifecycle, index design, performance tuning, backup/restore operations, and detailed Azure product comparisons are outside scope. T-SQL is illustrative and was not run on a server.
[What is SQL Server?](https://learn.microsoft.com/en-us/sql/sql-server/what-is-sql-server?view=sql-server-ver17)
[Microsoft SQL Database Engine overview](https://learn.microsoft.com/en-us/sql/database-engine/sql-database-engine?view=sql-server-linux-2017)
[Connect to the Database Engine](https://learn.microsoft.com/en-us/sql/sql-server/connect-to-database-engine?view=sql-server-ver17)
[Database files and filegroups](https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-files-and-filegroups?view=sql-server-ver17)
[The transaction log](https://learn.microsoft.com/en-us/sql/relational-databases/logs/the-transaction-log-sql-server?view=fabric-sqldb)
[Transaction log architecture and WAL](https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-transaction-log-architecture-and-management-guide?view=sql-server-ver17)
[BEGIN TRANSACTION](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/begin-transaction-transact-sql?view=azure-sqldw-latest)
[SET XACT_ABORT](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-xact-abort-transact-sql?view=sql-server-ver16)
[TRY...CATCH](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/try-catch-transact-sql?view=sql-server-ver17)
[Locking and row versioning](https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide?view=sql-server-ver15)