Sql Server string Prefix doubt [closed]

I’m learning T-SQL.
Why the strings are prefixed with N in every example I’ve seen?

What are the pros or cons of using this prefix?

Please make it clear that if my column has datatype as nvarchar /vachar then is it mandatory to provide values using ‘N’ as prefix or it just a system that we are following.

N’foo’ stores the string “foo” using Unicode.

‘foo’ stores it using ASCII.

This doesn’t matter if you’re just using a-zA-Z0-9, but will become necessary if you need to store other characters such as “រៀន”.

See also Write differences between varchar and nvarchar for more information.

If you are inserting the data into a field defined one way or the other, the system will usually convert the data automatically. Assigning ‘foo’ to an nvarchar field can be expected to work, but assigning N’រៀន’ to a varchar won’t.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *