views:

28

answers:

1

I am working through an example from MSDN that uses a small database to demonstrate data driven testing, and here is the simple schema:

CREATE TABLE dbo.LogonInfoTest
   (
   UserId nchar(256) NOT NULL PRIMARY KEY CLUSTERED,
   Password nvarchar(256) NULL,
   IsValid bit NOT NULL
   )  ON [PRIMARY]
GO

My question is: What is the underlying reason for choosing nchar as the datatype of UserId and nvarchar as the datatype of Password?

+5  A: 

There's no reason. The primary key should be NVARCHAR(256), as is hard for me to believe that the UserId will always be exactly 256 chars. Right now this schema is potentially wasting (a lot of) space on disk. Note that with SQL Server 2008 row-compression storage the fixed length column would be stored as a variable length one on disk anyway (trailing spaces are removed), but only if row-compression is enabled.

Remus Rusanu
thanks! if nobody says anything different i'll mark it the answer
Gabriel
Actually, having a 256 character, double-byte primary key (= 512 byte!) seems like a recipe for disaster.... Imagine how wide and bloated the clustered index and all non-clustered indices on that table will end up being!!
marc_s
interesting, still if I put myself in the authors shoes, I can't shake the feeling that he must have thought he had a reason there; it just feels deliberate. Oh well, I guess it's too small of a detail to dwell on.
Gabriel