开发者

Database - what is the different between 3 and N'3' in TSQL (Sql Server 2008)

Assuming ProductId is INT column, what is the difference between writing 3 and N'3'?

They both work fine.

INSERT INTO dbo.Products (ProductId, Name)开发者_如何转开发 VALUES (3,'Product3')

INSERT INTO dbo.Products (ProductId, Name) VALUES (N'3','Product3')


N'3' is a nvarchar type, where 3 is an int. If you're using nvarchar you're asking the parser to perform implicit conversion. In this case it works fine but in others you may run into casting problems.


When SQL Server encounters N'', it will treat the string as an NVARCHAR instead of VARCHAR. NVARCHAR fields are unicode.

The reason N'3' still works for you is because it is converting it to NVARCHAR, and then doing an implicit conversion to INT.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜