如下代码,我创建一张定长测试表,并写入1000行数据后
用sp_spaceused 查data为32KB,表示有4页,这个32KB是怎么计算出来的?
用DBCC PAGE查看Length 17,Record Size = 17 这个又是怎么计算的
create table tbtest (col1 char(10))--创建定长行测试表
go
insert into tbtest values ('1234567890')--写入1000笔定长记录
go 1000go
sp_spaceused 'tbtest'--查看数据存储空间大小
/*
name rows reserved data index_size unused
tbtest 1000 32 KB 24 KB 8 KB 0 KB
*/
dbcc page ('NewDB', 1, 432, 1)--查看数据页结构
/*
DATA:Slot 0, Offset 0x60, Length 17, DumpStyle BYTE
Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP Record Size = 17
Memory Dump @0x6211C060
00000000: 10000e00 31323334 35363738 39300100 †....1234567890..
00000010: 00†††††††††††††††††††††††††††††††††††.
*/
用sp_spaceused 查data为32KB,表示有4页,这个32KB是怎么计算出来的?
用DBCC PAGE查看Length 17,Record Size = 17 这个又是怎么计算的
create table tbtest (col1 char(10))--创建定长行测试表
go
insert into tbtest values ('1234567890')--写入1000笔定长记录
go 1000go
sp_spaceused 'tbtest'--查看数据存储空间大小
/*
name rows reserved data index_size unused
tbtest 1000 32 KB 24 KB 8 KB 0 KB
*/
dbcc page ('NewDB', 1, 432, 1)--查看数据页结构
/*
DATA:Slot 0, Offset 0x60, Length 17, DumpStyle BYTE
Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP Record Size = 17
Memory Dump @0x6211C060
00000000: 10000e00 31323334 35363738 39300100 †....1234567890..
00000010: 00†††††††††††††††††††††††††††††††††††.
*/
create table tbtest (col1 char(10))--创建定长行测试表
goinsert into tbtest values ('1234567890')--写入1000笔定长记录
go 1000DBCC SHOWCONTIG ('tbtest')
--> Pages Scanned: 3
(页面数+索引页数)*页大小=总大小(3 + 1) * 8K = 32K
declare @first binary(6)
select @first = first from sysindexes where id = object_id('tbtest') and indid in(0,1)
declare @PageNum int
select @PageNum = convert(int, substring(@first,4,1) + substring(@first,3,1) +
substring(@first,2,1) + substring(@first,1,1) )
declare @FileNum int
select @FileNum = convert(int, substring(@first,6,1) + substring(@first,5,1))
select @FileNum, @PageNum
--执行DBCC Page
declare @sql varchar(1000)
select @sql = 'dbcc page (''' + db_name() + ''', ' + convert(varchar(10),@FileNum) + ', ' +
convert(varchar(10),@PageNum) + ', 1)'
select @sql
dbcc traceon(3604)
exec (@sql)
Slot 4 Column 1 Offset 0x4 Length 10 Length (physical) 10
col1 = 1234567890 至于为何总长度是17, 详见SQL数据行的存储结构,含有系统的rowid之类的.