Getting ready for a SQL interview?

This post will help you revise the most important topics quickly and clearly — without long explanations or confusion. Think of this as your last-minute revision guide. Each question comes with a simple definition and a quick example to make it stick in your mind.

In Last-Minute SQL Interview Revision Guide – Part 1 (Keys, Data Types & Constraints), we’ll focus on the basics — the foundation every SQL developer must know before the interview.

Let’s begin your quick refresh and make sure you walk into the interview confident and ready!

What is SQL?

SQL (Structured Query Language) is a standard language for storing, retrieving, managing, and manipulating data in a relational database. It includes commands for defining structures (DDL), querying data (DQL), modifying data (DML), controlling access (DCL), and transaction management (TCL).

What is a Database?

A database is an organized collection of related data that can be easily accessed, managed, and updated. It allows users to store, retrieve, and manipulate data efficiently using a Database Management System (DBMS).

Example

What is a row/record?

A row (or record) in a database table is a single, complete set of related data stored horizontally. Each row represents one entity or instance in the table, with columns defining its attributes.

EmployeeIDFirstNameLastNameDepartmentSalary
101RajBhattIT50000

The first row (101, Raj, Bhatt, IT, 50000) is one record representing one employee.

Quick Recall

What is a column/field?

A column (or field) in a database table is a vertical structure that defines a specific attribute of the table. Each column has a name and data type, and it holds data for that attribute across all rows/records.

EmployeeIDFirstNameLastNameDepartmentSalary
101RajBhattIT50000

Quick Recall

What is a primary key?

A Primary Key (PK) is a column or a combination of columns in a table that uniquely identifies each record. It cannot contain NULL values, and no two rows can have the same primary key value.

EmployeeIDFirstNameLastNameDepartmentSalary
101RajBhattIT50000
102PriyaSharmaHR45000

Quick Recall

What is a foreign key?

A Foreign Key (FK) is a column (or set of columns) in one table that refers to the primary key in another table. It establishes a relationship between two tables and ensures referential integrity, meaning that a value in the foreign key must exist in the referenced primary key.

Employee Table

EmployeeIDFirstNameLastNameDeptID
101RajBhatt1
102PriyaSharma2

Department Table

DeptIDDeptName
1IT
2HR

Quick Recall

What is a unique key?

A Unique Key ensures that all values in a column or combination of columns are unique. Unlike a primary key, a table can have multiple unique keys and it can allow one NULL.

CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY,
    Email VARCHAR(100) UNIQUE
);

What is a Composite key?

A Composite Key is a combination of two or more columns used together as a primary key to uniquely identify a record.

CREATE TABLE Orders (
    OrderID INT,
    ProductID INT,
    Quantity INT,
    PRIMARY KEY (OrderID, ProductID)
);

What is a Constraints?

A Constraint is a rule applied to a column or table to control the type of data allowed, ensuring accuracy, consistency, and integrity in the database.

Common Types of Constraints

ConstraintPurpose
PRIMARY KEYUniquely identifies each row
FOREIGN KEYEnsures relationship integrity between tables
UNIQUEPrevents duplicate values
NOT NULLColumn must have a value
CHECKEnsures values meet a specific condition
DEFAULTAssigns a default value if none is provided
CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY,
    Email VARCHAR(100) UNIQUE,
    FirstName VARCHAR(50) NOT NULL,
    LastName VARCHAR(50) NOT NULL,
    Salary DECIMAL CHECK(Salary > 0),
    DeptID INT NOT NULL DEFAULT 1,
    FOREIGN KEY (DeptID) REFERENCES Departments(DeptID)
);

Quick Recall

What is a Candidate Key?

A Candidate Key is a column or a set of columns in a table that can uniquely identify each row. Every table can have one or more candidate keys, but only one is chosen as the primary key.

Employee Table

EmployeeIDEmailPhoneNumberFirstNameLastName
101[email protected]9876543210RajBhatt
102[email protected]9876543211PriyaSharma

Quick Recall

What is a surrogate key?

A Surrogate Key is a system-generated unique identifier for a table row, often an auto-increment integer. It is used when no natural or candidate key is suitable or when we want a simpler primary key unrelated to business data.

EmployeeID is a surrogate key:

Quick Recall

What is a Natural key?

A Natural Key is a column or a set of columns that uniquely identifies a record based on real-world, meaningful data. It differs from a surrogate key because it is derived from the actual data, not generated by the system.

Employee Table

EmailFirstNameLastNameDeptID
[email protected]RajBhatt1
[email protected]PriyaSharma2

Quick Recall

What is Alternate Key ?

An Alternate Key is a candidate key that was not selected as the primary key but can still uniquely identify records in a table. it serves as a backup unique identifier.

Employee Table

Employee IDEmailPhone Number
101[email protected]9876543210
102[email protected]9876543211

Quick Recall

What is Super Key ?

A Super Key is a column or combination of columns that can uniquely identify each row in a table. It may include extra attributes beyond what is strictly necessary to ensure uniqueness.

Employee Table

EmployeeIDEmailPhoneNumberDeptID
101[email protected]98765432101
102[email protected]98765432112

Quick Recall

What is a schema ?

A Schema in SQL is a logical container or namespace that groups related database objects like tables, views, stored procedures, functions, and indexes.

It helps organize the database and manage security and ownership efficiently.

CREATE SCHEMA HR;
GO

CREATE TABLE HR.Employees (
    EmployeeID INT PRIMARY KEY,
    Name VARCHAR(100),
    Email VARCHAR(100)
);

Quick Recall

Is a schema the same as a database?

No, a database is a collection of data and objects, while a schema is a logical grouping inside the database that organizes those objects.

What is a data type?

A data type in SQL defines the kind of value that a column, variable, or parameter can hold. It ensures data consistency, memory efficiency, and validation of data stored in a database.

CREATE TABLE Employees (
    EmployeeID INT,
    Name VARCHAR(100),
    Salary DECIMAL(10,2),
    JoiningDate DATETIME
);

Quick Recall

Common SQL Server Data Type Categories

CategoryExamplesDescription
NumericINT, BIGINT, DECIMAL, FLOATStore numbers
Character/StringCHAR, VARCHAR, TEXTStore text
Date/TimeDATE, DATETIME, TIMEStore date/time values
BinaryBINARY, VARBINARYStore binary data (e.g., images)
BooleanBITStore true/false (0/1)
SpecialUNIQUEIDENTIFIER, XML, JSONStore unique IDs or structured data

Why are data types important?

They define storage format, prevent invalid data, and improve database performance by optimizing memory usage.

What is the difference between CHAR and VARCHAR?

CHAR is a fixed-length data type, meaning it always stores the same amount of space, even if the data is shorter.

VARCHAR is a variable-length data type, meaning it uses only the space required for actual data.

CREATE TABLE Example (
    Code CHAR(10),
    Name VARCHAR(10)
);

INSERT INTO Example VALUES ('A1', 'A1');
ColumnStored ValueStorage Behavior
Code (CHAR)'A1 'Occupies 10 bytes (fixed)
Name (VARCHAR)'A1'Occupies only 2 bytes (actual length)

Key Differences Between CHAR and VARCHAR

FeatureCHARVARCHAR
Storage TypeFixed-lengthVariable-length
PerformanceFaster for fixed-size dataBetter for variable-size data
Storage SpaceAlways uses full defined lengthUses only required space
PaddingPads with spaces to match defined lengthNo padding
Use CaseIdeal for codes, status, gender, etc.Ideal for names, addresses, descriptions
ExampleCHAR(5) always = 5 bytesVARCHAR(5) = actual data length only

Which one is better, CHAR or VARCHAR?

What is INT?

INT (short for Integer) is a numeric data type in SQL used to store whole numbers (both positive and negative) without decimal places. It is commonly used for IDs, counts, or quantities.

CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY,
    Age INT,
    Salary DECIMAL(10,2)
);
PropertyDescription
TypeInteger (whole number)
Storage Size4 bytes
Range (Signed)-2,147,483,648 to 2,147,483,647
Range (Unsigned)0 to 4,294,967,295 (in MySQL)
DefaultSigned
Decimal Allowed?No (use DECIMAL or FLOAT if needed)

When Int?

What’s the difference between INT, BIGINT, SMALLINT, and TINYINT?

They all store whole numbers but differ in storage size and range —TINYINT (1 byte), SMALLINT (2 bytes), INT (4 bytes), BIGINT (8 bytes).Choose based on how large the numbers can grow.

What is Decimal?

DECIMAL is a fixed-point numeric data type in SQL used to store exact numeric values with a defined precision (total digits) and scale (digits after the decimal point). It is used where accuracy is crucial — like in financial or accounting data.

CREATE TABLE Products (
    ProductID INT PRIMARY KEY,
    Price DECIMAL(10,2)
);
PropertyDescription
TypeExact numeric (fixed-point)
SyntaxDECIMAL(p, s) or NUMERIC(p, s)
Precision (p)Total number of digits (1–38 in SQL Server)
Scale (s)Digits after the decimal point
Storage SizeDepends on precision (5–17 bytes)
AccuracyExact (no rounding errors like FLOAT)
AliasNUMERIC (same behavior in SQL Server)

When to Use DECIMAL

What’s the difference between DECIMAL and FLOAT?

DECIMAL stores exact values with fixed precision — ideal for money. FLOAT stores approximate values using binary representation — better for scientific or large-scale calculations where minor precision loss is acceptable.

What is Date?

The DATE data type in SQL is used to store calendar dates (year, month, and day) without any time information. It is ideal for storing birthdays, joining dates, deadlines, and other date-only information.

Storage

Usage Scenarios

Comparison Table

Data TypeStoresExampleStorage
DATEDate only2025-10-103 bytes
DATETIMEDate + time2025-10-10 12:30:458 bytes
DATETIME2Date + time with higher precision2025-10-10 12:30:45.12345676–8 bytes

What is NULL?

In SQL, NULL represents a missing, unknown, or undefined value in a table column. It does not mean zero (0), empty string (''), or false — it simply means “no data.

Important Notes

ConceptDescription
NULL ≠ NULLTwo NULLs are not equal because both represent unknown values.
Use IS NULLTo check if a value is null.
AggregatesFunctions like COUNT(), SUM(), AVG() ignore NULLs.
Default valuesIf no value is provided for a column that allows NULLs → SQL stores NULL automatically.

Difference Between Empty and NULL

-- Empty string
INSERT INTO Employees (EmployeeID, Name, Email)
VALUES (2, 'Ravi', '');

-- NULL value
INSERT INTO Employees (EmployeeID, Name, Email)
VALUES (3, 'Amit', NULL);

'' = “known empty” (a blank string)

NULL = “unknown” (no value at all)

What is NOT NULL?

The NOT NULL constraint in SQL ensures that a column cannot have a NULL value. It means the column must always contain a valid value — no blanks, no unknowns.

NOT NULL is a column-level constraint used to enforce data integrity by making sure every row has a value for that column.

CREATE TABLE Employees (
    EmployeeID INT NOT NULL,
    Name VARCHAR(50) NOT NULL,
    Email VARCHAR(100) NULL
);

INSERT INTO Employees (EmployeeID, Name, Email)
VALUES (1, 'Raj', NULL);  -- Valid (Email allows NULL)

INSERT INTO Employees (EmployeeID, Name)
VALUES (NULL, 'Ravi');    -- Error (EmployeeID cannot be NULL)

What is a default value?

The DEFAULT constraint in SQL is used to assign an automatic value to a column when no value is specified during an INSERT operation. It ensures that every record has a valid value — even if the user doesn’t explicitly provide one.

CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY,
    Name VARCHAR(50) NOT NULL,
    JoiningDate DATE DEFAULT GETDATE(),
    IsActive BIT DEFAULT 1
);
INSERT INTO Employees (EmployeeID, Name)
VALUES (1, 'Raj');

Important Notes

We’ve reached the end of Last-Minute SQL Interview Revision Guide – Part 1 (Keys, Data Types & Constraints) . Here, we focused on the core concepts that form the foundation of SQL knowledge .These are the building blocks that every SQL developer must know. Mastering them will make it easier to tackle advanced topics in upcoming interviews.

Remember: Revision is more effective when it’s short and consistent. Go through these notes, try out a few queries, and you’ll be confident in explaining them during interviews.

Thank you for taking the time to read this post. I hope it has given you a clear and concise understanding of SQL Keys, Data Types, and Constraints. Mastering these concepts is essential for interview success, as they form the foundation of relational database design and querying. By revising these definitions, examples, and best practices, you ensure that you are well-prepared, confident, and ready to answer both basic and advanced SQL questions in interviews.

Happy revising, and may your next SQL interview be a success!!!