ShuDudu's Home was started in 2011, but the web data is lost, so now begin again, I would like to make some friends, I hope you like ShuDudu's home.
Current position: ShuDudu > Life >

[MSSQL] The difference between Varchar and char

Thursday on January 1st, 1970Life

That day, I was talking about the difference between Varchar and char in MS SQL Server, and I felt confused. It's better to record it. A good memory is not as good as a bad keyboard.

Varchar takes up 2 bytes for each English (ASCII) character, and only 2 bytes for a Chinese character. Char takes up 1 byte for an English (ASCII) character, and 2 bytes for a Chinese character. The type of Varchar is not filled with spaces, such as varchar(100), but its value is only "qian", so its value is "qian" and char is different. For example, char(100), its value is "qian", but in fact it is "qian" in the database (There are 96 spaces after qian, which means filling it to 100 bytes).
Since char is of fixed length, it will be much faster than varchar! But it's a bit more troublesome to process the program. You need to use a function such as trim to remove the spaces on both sides!

Copyright Protection: ShuDudu from the original article, reproduced Please keep the link: https://www.shududu.com/life/MSSQL-The-difference-between-Varchar-and-char.htm