Describe the Elements of a basic SQL-Server Database
Elements of a Database in SQL-Server 2022.
In SQL Server 2022, a database is a structured collection of data and its associated components used to store, retrieve, and manage information efficiently. Below are the core elements of a database in SQL Server:
Database Files
Primary Data File (.mdf): Stores the main data and objects.
Secondary Data File(s) (.ndf)(optional): Used to spread data across disks.
Transaction Log File (.ldf): Records all transactions and database modifications to ensure data recovery.
Schemas
A schema is a container that holds database objects like tables and views.
Helps in organizing and managing permissions separately from the objects themselves.
Tables
Core element where data is stored in rows and columns.
Types:
Heap Table: No clustered index.
Clustered Table: Has a clustered index.
Indexes
Improve data retrieval speed.
Types:
Clustered Index: Alters the physical order of data.
Non-clustered Index: Logical structure separate from the data.
Views
Virtual tables representing the result of a SQL query.
Do not store data but allow simplified querying and security control.
Stored Procedures
Precompiled SQL code blocks that perform operations like INSERT, UPDATE, or SELECT.
Improve performance and reusability.
Functions
Similar to stored procedures but return a value.
Scalar functions return a single value, table-valued functions return a table.
Triggers
Special stored procedures that automatically execute in response to certain events on a table or view (e.g., INSERT, UPDATE, DELETE).
Constraints
Rules enforced on data columns to maintain data integrity.
Primary Key
Foreign Key
Unique
Check
Default
Users and Roles
Manage security through permissions assigned to database users and roles.
Temporal Tables(Newer feature)
Automatically track history of data changes, supporting data auditing and recovery.
Synonyms
Aliases for database objects, simplifying access and abstraction.
Service Broker, Full-Text Search, and CLR Integration
Service Broker: Enables message-based communication within the database.
CLR Integration: Supports running .NET code within SQL Server.
🧾 Conclusion
SQL Server 2022 databases are built from a combination of data structures, procedural logic, security elements, and system files. Together, they enable robust, secure, and scalable data management for enterprise-level applications.
SQL Server Management Studio (SSMS) - Database Properties
The image is a screenshot from SQL Server Management Studio (SSMS) showing the Database Properties window for a database named `EtechDB`. This dialog is typically accessed by right-clicking a database in Object Explorer and choosing "Properties."
📋 Extracted Text from the Image Path Navigation (Left Panel):
Select a page:
- General
- Files
- Filegroups
- Options
- Change Tracking
- Permissions
- Extended Properties
- Mirroring
- Transaction Log Shipping
- Query Store
Main Details (Right Panel):
Backup
- Last Database Backup: None
- Last Database Log Backup: None
Database
- Name: EtechDB
- Status: Normal
- Owner: NISARG-PC\Nisarg
- Date Created: 30-03-2021 23:31:46
- Size: 16.00 MB
- Space Available: 5.70 MB
- Number of Users: 4
- Memory Allocated To Memory Optimized Obj: 0.00 MB
- Memory Used By Memory Optimized Objects: 0.00 MB
Maintenance
- Collation: SQL_Latin1_General_CP1_CI_AS
Bottom Help Text (Context-sensitive help for selected field):
Name
The name of the database.
🧠Interpretation
This image represents the properties dialog for a database in SQL Server. It provides metadata and configuration information for the database named EtechDB, including:
Database Owner: NISARG-PC\Nisarg (a Windows authenticated login)
Database Status: Normal
Creation Date: March 30, 2021
Size Information: Total size, free space
User Info: Number of users connected
Memory: Memory optimized objects are not used
Collation: Default collation setting is SQL_Latin1_General_CP1_CI_AS
This screen is essential for DBAs to verify settings, diagnose configuration issues, or change ownership and maintenance options.
Before you can create any objects to contain or manage your data, you must create a database to act as a container for those objects. In this lesson, you will create a database that we will build on during the rest of this course. The biggest consideration in creating a database is its size. This is the maximum amount of disk space the database will consume.
SQL Server has the ability to allocate space dynamically for databases. I highly recommend this, it is better to have SQL Server allocate more space than necessary than for you to receive a critical error indicating that you ran out of disk space when you are trying to save data.
Along with a database is an object that works "behind the scenes" called a transaction log. A transaction log is used to store data when a query is managed within a transaction. The transaction log preserves the state of the data at the point when the transaction is started. Transactions are discussed in another course in this series. For now, it is just important to know that the transaction log exists.
To create a database, use the Transact-SQL statement CREATE DATABASE. This is described in an upcoming lesson.
You can also create a database by clicking the name of your server in the Enterprise Manager. From the Action menu, select New, then select Database to display the Database Properties dialog, illustrated below.
SQL Server 2022 makes use of Transaction Log
SQL Server 2022 absolutely makes use of a transaction log when creating a database—just as all versions of SQL Server have since its inception.
✅ Here's what happens when you create a database in SQL Server 2022:
Two essential files are created:
Primary Data File (.mdf) — stores schema and data.
Transaction Log File (.ldf) — records all transactions and database modifications.
The transaction log (.ldf) is critical for:
Ensuring ACID compliance, especially durability and atomicity.
Rolling back uncommitted transactions in case of a failure.
Recovery of the database after a crash or restart.
Transactional replication, log shipping, and other high availability features.
The transaction log is created immediately during the CREATE DATABASE command, even if you don’t explicitly define it:
CREATE DATABASE SalesDB;
The engine automatically creates:
SalesDB.mdf
SalesDB_log.ldf
📌 Example of specifying your own log file:
CREATE DATABASE SalesDB
ON
( NAME = SalesDB_Data,
FILENAME = 'C:\SQLData\SalesDB.mdf',
SIZE = 20MB,
MAXSIZE = 200MB,
FILEGROWTH = 5MB )
LOG ON
( NAME = SalesDB_Log,
FILENAME = 'C:\SQLLogs\SalesDB.ldf',
SIZE = 10MB,
MAXSIZE = 100MB,
FILEGROWTH = 5MB );
🧠In Summary:
The transaction log is mandatory and automatically used by SQL Server 2022.
You can control its size, growth, and location, but you cannot create a database without it.
It is vital for recovery, rollback, replication, and auditing.
Database properties dialog
In the next lesson, you will learn how to use Transact-SQL to create a database.