Solve the problem: if the field type is char, it always occupies the specified byte length (many white spaces at the end). The varchar data type length is one Chinese character, which occupies 2 bytes, we recommend that you use nvarchar for all fields whose content is stored in Chinese. Operation Description: Open SQLServerManagementStudio, select the database for which you want to update the field type, and click Create query menu.
Solve the problem: if the field type is char, it always occupies the specified byte length (many white spaces at the end). The varchar data type length is one Chinese character, which occupies 2 bytes, we recommend that you use nvarchar for all fields whose content is stored in Chinese. Operation Description: Open SQL Server Management Studio, select the database for which you want to update the field type, and click Create query menu.
Solve the problem: if the field type is char, it always occupies the specified byte length (many white spaces at the end). The varchar data type length is one Chinese character, which occupies 2 bytes, we recommend that you use nvarchar for all fields whose content is stored in Chinese.
Operation Description: Open SQL Server Management Studio, select the database for which you want to update the field type, click the new query menu, and execute the following statement.
Code details:
-- Replace all user data tables in the database with scripts whose field data types are char and varchar to nvarchar in batches
Declare @ cllength nvarchar (8) -- defines the field length variable
Open mycursor1 -- open the cursor
-- Declare all Constraints List cursor corresponding to the specified field in the read data table
-- 2 execute the update field statement cyclically
Close mycursor1 -- close the cursor