我想知道 SQL Server 如何在内部处理 varchar
动态长度和存储。
如果我知道列中有固定长度的字符,使用 Varchar
是否有益?
我知道 CHAR
和 VARCHAR
之间的区别,但是在大数据库中使用 CHAR
或 VARCHAR 进行数据库设计的最佳方法是什么
?
最佳答案
CHAR 在行中分配其大小,VARCHAR 存储字符串的实际大小(2 字节),然后是实际字符串,因此 varchar 的开销是 +2 字节,而 CHAR 的开销是 - 它的大小减去实际字符串长度。如果在 varchar 中存储 NULL 值 - 它在 db 中的大小为零。
record header 4 bytes long two bytes of record metadata (record type) two bytes pointing forward in the record to the NULL bitmap fixed length portion of the record, containing the columns storing data types that have fixed lengths (e.g. bigint, char(10), datetime) NULL bitmap two bytes for count of columns in the record variable number of bytes to store one bit per column in the record, regardless of whether the column is nullable or not (this is
different and simpler than SQL Server 2000 which had one bit per nullable column only) this allows an optimization when reading columns that are NULL variable-length column offset array two bytes for the count of variable-length columns two bytes per variable length column, giving the offset to the end of the column value versioning tag this is in SQL Server 2005 only and is a 14-byte structure that contains a timestamp plus a pointer into the version store in tempdb
关于sql-server - SQL Server 内部是如何处理 Varchar 的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9339386/