0

We are designing a new database, and need to know if a nvarchar(n) column will use any bytes to store a null value?

  1. If a nvarchar(n) column stores a null value, how many bytes are used?

  2. How many bytes are used to store and empty string in a nvarchar(n)? (i.e."")

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
Sean
  • 115
  • 6

2 Answers2

0

Empty string will use 2 bytes. More details at: nchar-and-nvarchar
NULL will use 1 bit in the NULL bitmap.

Piotr
  • 2,753
  • 1
  • 6
  • 15
0

It is a physical implementation detail, so it could be different for Oracle an for SQL Server. With SQL Server, NULLs a represented with a single bit in the null bitmap (one bit for each nullable column). An empty string, be it varchar or nvarchar, it's two bytes. Hope someone from Oracle side will complement.

dean
  • 9,349
  • 2
  • 19
  • 22
  • 2
    _"Hope someone from Oracle side will complement"_. In Oracle, a `null` value takes 1 byte in block, unless it is at the end of the row (or all the values following it in the row are all `null` as well), in which case it takes zero bytes. – Matthew McPeak Sep 20 '19 at 18:20