开发者

Is there a reason that the primary key is nchar while other fields are nvarchar?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜