SQL Server Interview Question #21
What are data types in SQL Server?
Data Types, Keys & Constraints Junior Beginner
Detailed Explanation
A data type defines what kind of value a column, variable, or parameter can store. Choosing the correct data type improves data integrity, storage efficiency, indexing, and query performance.
Common SQL Server data types include INT and BIGINT for integers; DECIMAL for exact numeric values; VARCHAR and NVARCHAR for text; DATE, DATETIME2, and TIME for date/time values; BIT for Boolean-style values; UNIQUEIDENTIFIER for GUIDs; and VARBINARY for binary data.
In production systems, use the smallest appropriate type that correctly represents the business data.
Code Example
CREATE TABLE Products
(
Id INT IDENTITY(1,1) PRIMARY KEY,
Name NVARCHAR(200) NOT NULL,
Price DECIMAL(18,2) NOT NULL,
IsActive BIT NOT NULL,
CreatedAt DATETIME2 NOT NULL
);