标签:style blog color os ar strong for 数据 div
一、插入无序GUID数据
1 --创建表并插入无序GUID数据 2 --DROP TABLE T_PROORDERTYPEGUIDTEST; 3 create table T_PROORDERTYPEGUIDTEST ( 4 FENTRYID varchar(36) not null default ‘ ‘, 5 FPROORDERENTRYID int not null default 0, 6 FPROORDERTYPE varchar(20) not null default ‘ ‘, 7 FFORMID varchar(36) not null default ‘ ‘, 8 FNUMBER nvarchar(160) not null default ‘ ‘, 9 FCREATEORGID int not null default 0, 10 FUSEORGID int not null default 0, 11 FDOCUMENTSTATUS char(1) not null default ‘C‘, 12 FFORBIDSTATUS char(1) not null default ‘A‘, 13 FDATE datetime not null default getdate(), 14 FMATERIALID int not null default 0, 15 FBOMID int not null default 0, 16 FAUXPROPID int not null default 0, 17 FLOT int not null default 0, 18 FMtoNo nvarchar(200) not null default ‘‘, 19 FSEQ int not null default 0, 20 FUNITID int not null default 0, 21 FPRODUCTID int not null default 0, 22 FWORKSHOPID int not null default 0, 23 FCOSTCENTERID int not null default 0, 24 constraint PK_PROORDERTYPE primary key (FENTRYID) 25 ) 26 --插入500000条数据 27 declare @i int 28 set @i = 1 29 while @i < 500000 30 begin 31 INSERT INTO T_PROORDERTYPEGUIDTEST(FENTRYID,FPROORDERENTRYID,FPROORDERTYPE,FFORMID,FNUMBER,FCREATEORGID, 32 FUSEORGID,FDOCUMENTSTATUS,FFORBIDSTATUS,FDATE,FMATERIALID,FBOMID,FAUXPROPID,FLOT, 33 FSEQ,FUNITID,FPRODUCTID,FWORKSHOPID,FCOSTCENTERID) values 34 (NEWID(),@i,‘PO‘,‘FORM_OUTSRCPROORDER‘,‘TEST00001‘,@i,@i,‘C‘,‘A‘,GETDATE(),@i,@i,@i,@i,@i,@i,@i,@i,@i) 35 SET @i=@i+1 36 end ; 37 38 select COUNT(1) from T_PROORDERTYPEGUIDTEST
二、插入有序GUID数据
1 --创建表并插入有序GUID数据 2 DROP TABLE T_PROORDERTYPESEQGUIDTEST; 3 create table T_PROORDERTYPESEQGUIDTEST ( 4 FENTRYID uniqueidentifier not null default (NEWSEQUENTIALID()), 5 FPROORDERENTRYID int not null default 0, 6 FPROORDERTYPE varchar(20) not null default ‘ ‘, 7 FFORMID varchar(36) not null default ‘ ‘, 8 FNUMBER nvarchar(160) not null default ‘ ‘, 9 FCREATEORGID int not null default 0, 10 FUSEORGID int not null default 0, 11 FDOCUMENTSTATUS char(1) not null default ‘C‘, 12 FFORBIDSTATUS char(1) not null default ‘A‘, 13 FDATE datetime not null default getdate(), 14 FMATERIALID int not null default 0, 15 FBOMID int not null default 0, 16 FAUXPROPID int not null default 0, 17 FLOT int not null default 0, 18 FMtoNo nvarchar(200) not null default ‘‘, 19 FSEQ int not null default 0, 20 FUNITID int not null default 0, 21 FPRODUCTID int not null default 0, 22 FWORKSHOPID int not null default 0, 23 FCOSTCENTERID int not null default 0, 24 constraint PK_SEQPROORDERTYPE primary key (FENTRYID) 25 ) 26 --插入500000条数据 27 declare @i int 28 set @i = 1 29 while @i < 500000 30 begin 31 INSERT INTO T_PROORDERTYPESEQGUIDTEST(FPROORDERENTRYID,FPROORDERTYPE,FFORMID,FNUMBER,FCREATEORGID, 32 FUSEORGID,FDOCUMENTSTATUS,FFORBIDSTATUS,FDATE,FMATERIALID,FBOMID,FAUXPROPID,FLOT, 33 FSEQ,FUNITID,FPRODUCTID,FWORKSHOPID,FCOSTCENTERID) values 34 (@i,‘PO‘,‘FORM_OUTSRCPROORDER‘,‘TEST00001‘,@i,@i,‘C‘,‘A‘,GETDATE(),@i,@i,@i,@i,@i,@i,@i,@i,@i) 35 SET @i=@i+1 36 end ; 37 38 select COUNT(1) from T_PROORDERTYPESEQGUIDTEST
三、分析索引碎片
1 --分析索引碎片 2 declare @table_id int 3 set @table_id=object_id(‘T_PROORDERTYPEGUIDTEST‘) 4 dbcc showcontig(@table_id);
DBCC SHOWCONTIG 正在扫描 ‘T_PROORDERTYPEGUIDTEST‘ 表...
表: ‘T_PROORDERTYPEGUIDTEST‘ (410536596);索引 ID: 1,数据库 ID: 8
已执行 TABLE 级别的扫描。
- 扫描页数................................: 13933
- 扫描区数..............................: 1759
- 区切换次数..............................: 13932
- 每个区的平均页数........................: 7.9
- 扫描密度 [最佳计数:实际计数].......: 12.50% [1742:13933]
- 逻辑扫描碎片 ..................: 99.22%
- 区扫描碎片 ..................: 0.11%
- 每页的平均可用字节数.....................: 2569.6
- 平均页密度(满).....................: 68.25%
DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。
1 declare @table_id int 2 set @table_id=object_id(‘T_PROORDERTYPESEQGUIDTEST‘) 3 dbcc showcontig(@table_id)
DBCC SHOWCONTIG 正在扫描 ‘T_PROORDERTYPESEQGUIDTEST‘ 表...
表: ‘T_PROORDERTYPESEQGUIDTEST‘ (1114539104);索引 ID: 1,数据库 ID: 8
已执行 TABLE 级别的扫描。
- 扫描页数................................: 8197
- 扫描区数..............................: 1033
- 区切换次数..............................: 1032
- 每个区的平均页数........................: 7.9
- 扫描密度 [最佳计数:实际计数].......: 99.23% [1025:1033]
- 逻辑扫描碎片 ..................: 0.67%
- 区扫描碎片 ..................: 0.10%
- 每页的平均可用字节数.....................: 44.3
- 平均页密度(满).....................: 99.45%
DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。
[O]SQL SERVER下有序GUID和无序GUID作为主键&聚集索引的性能表现
标签:style blog color os ar strong for 数据 div
原文地址:http://www.cnblogs.com/springwind268/p/3984175.html