Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SQL Server give me a column twice the size I requested?

After executing a CREATE TABLE for a temporary table I was verifying that the size of the field fits what I need to use.

To my surprise, SQL Server (Azure SQL) is reporting that the table now has double the size. Why is this?

This is what I executed, in order:

CREATE TABLE #A ( Name NVARCHAR(500) not null ) 
EXEC tempdb..sp_help '#A'

double the size

like image 604
Alpha Avatar asked Sep 19 '25 01:09

Alpha


1 Answers

An NVARCHAR column in SQL Server always stores every character with 2 bytes.

So if you're asking for 500 characters (at 2 bytes each), obviously this results in column size of 1000 bytes.

That's been like this in SQL Server forever - this isn't new or Azure specific.

like image 153
marc_s Avatar answered Sep 21 '25 22:09

marc_s