SQL Server Interview Question #8
What is a schema in SQL Server?
SQL Server Fundamentals Junior Beginner
Detailed Explanation
A schema is a logical namespace or container for database objects such as tables, views, stored procedures, and functions. Schemas help organize objects, separate names, and manage permissions.
In dbo.Products, dbo is the schema and Products is the table. Custom schemas such as Sales or HR can also be created.
Code Example
CREATE SCHEMA Sales;
GO
CREATE TABLE Sales.Orders
(
Id INT PRIMARY KEY,
OrderDate DATETIME2 NOT NULL
);