Microsoft Azure Data FundamentalsDescribe how to work with relational data on AzureEasy
A developer is creating a new table in an Azure SQL Database to store product details. One of the columns, 'ProductName', needs to store variable-length string data that can include Unicode characters and can be up to 255 characters long. Which data type should be used for this column?
- ANVARCHAR(255)
- BTEXT
- CVARCHAR(255)
- DCHAR(255)
Show answer & explanationAnswer & explanation
Correct answer: A. NVARCHAR(255)
NVARCHAR(n) stores variable-length Unicode string data up to 'n' characters. Since the requirement specifies Unicode characters and a maximum length, NVARCHAR is the correct choice.
Why the other options are wrong
- B. TEXT is a legacy data type for very large non-Unicode strings and is generally not recommended for new development where NVARCHAR(MAX) or VARCHAR(MAX) are preferred.
- C. VARCHAR(n) stores variable-length non-Unicode string data.
- D. CHAR(n) stores fixed-length non-Unicode string data, which is inefficient for variable-length data and does not support Unicode.
NVARCHAR Data Type
NVARCHAR is a variable-length Unicode string data type in SQL Server, suitable for text that includes characters from multiple languages.
- Stores Unicode characters.
- Variable-length, saves space.
- Maximum length up to 4000 characters or MAX.
Memory trick: N for National/Unicode, VAR for Variable.