SQL

SQL Data Types Interview Questions

3 questions with answers · SQL Interview Guide

CHAR vs VARCHAR vs NVARCHAR, numeric types, date/time types, and collation. Understanding data types prevents common bugs.

bar_chartQuick stats
Total questions3
High frequency1
With code examples1
1

Difference between char varchar and nvarchar in sql server

CHAR is fixed-length and always allocates the declared size, padding shorter values with spaces. CHAR(50) always uses 50 bytes regardless of the actual content length. VARCHAR is variable-length and only uses the space needed plus 1-2 bytes of overhead, making it more storage-efficient for variable-length data. NVARCHAR is like VARCHAR but stores Unicode characters using 2 bytes per character, so NVARCHAR(50) can use up to 100 bytes. Use CHAR for fixed-length data like country codes, VARCHAR for regular text, and NVARCHAR when you need to support multiple languages.

2

What is collation

Collation defines the rules for how string data is sorted and compared in the database, covering things like character set, case sensitivity, and accent sensitivity. For example, with a case-insensitive collation, 'Apple' and 'apple' are treated as equal in a WHERE clause or ORDER BY. You can set collation at the server, database, column, or even expression level. Mismatched collations between columns in a JOIN can cause errors or unexpected behavior, which is a common gotcha when working with multiple databases.

sql
-- Column with specific collation
CREATE TABLE products (
    name VARCHAR(100) COLLATE SQL_Latin1_General_CP1_CI_AS  -- CI = case insensitive
);

-- Comparing with explicit collation
SELECT * FROM products WHERE name COLLATE Latin1_General_CS_AS = 'Widget';
3

What are all different types of collation sensitivity

Collation sensitivity in SQL Server controls how string data is compared and sorted. Case sensitivity (CS vs CI) determines whether 'A' and 'a' are treated as different. Accent sensitivity (AS vs AI) controls whether accented characters like 'é' and 'e' are distinct. Kana sensitivity (KS) differentiates Japanese Hiragana and Katakana characters. Width sensitivity (WS) distinguishes between single-byte and double-byte representations of the same character. You'll see these abbreviated in collation names, for example SQL_Latin1_General_CP1_CI_AS means case-insensitive and accent-sensitive.

Knowing the answers is half the battle

The other half is explaining them clearly under pressure.

Try a free mock interviewarrow_forward

More SQL topics