Create table TestChar (Id Int Identity Key(1,1) Primary key, Name char(100))
Create table TestVarchar (Id Int Identity Key(1,1) Primary key, Name varchar(100))
Let's assume we have inserted 1,00,000 rows into both tables, populating the Name column with NULL.
dbcc showcontig(TestChar)
DBCC SHOWCONTIG scanning 'TestChar' table...
Table: 'TestChar' (165575628); index ID: 1, database ID: 10
TABLE level scan performed.
- Pages Scanned................................: 1409
- Extents Scanned..............................: 178
- Extent Switches..............................: 177
- Avg. Pages per Extent........................: 7.9
- Scan Density [Best Count:Actual Count].......: 99.44% [177:178]
- Logical Scan Fragmentation ..................: 0.00%
- Extent Scan Fragmentation ...................: 0.00%
- Avg. Bytes Free per Page.....................: 76.2
- Avg. Page Density (full).....................: 99.06%
DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
dbcc showcontig(TestVarchar)
DBCC SHOWCONTIG scanning 'TestVarchar' table...
Table: 'TestVarchar' (197575742); index ID: 1, database ID: 10
TABLE level scan performed.
- Pages Scanned................................: 161
- Extents Scanned..............................: 21
- Extent Switches..............................: 20
- Avg. Pages per Extent........................: 7.7
- Scan Density [Best Count:Actual Count].......: 100.00% [21:21]
- Logical Scan Fragmentation ..................: 0.00%
- Extent Scan Fragmentation ...................: 0.00%
- Avg. Bytes Free per Page.....................: 21.5
- Avg. Page Density (full).....................: 99.73%
DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
Then I have updated the two tables with the following statement:
Update Testchar
set name ='this is an interesting note that I came across recently.Most of our database design'
Update Testvarchar
set name ='this is an interesting note that I came across recently.Most of our database design'
Executing dbcc Showcontig again, the output for table Testchar remains the same as shown above, but the output varies greatly for table Testvarchar:
dbcc showcontig(TestVarchar)
DBCC SHOWCONTIG scanning 'testVarchar' table...
Table: 'testVarchar' (197575742); index ID: 1, database ID: 10
TABLE level scan performed.
- Pages Scanned................................: 1596
- Extents Scanned..............................: 201
- Extent Switches..............................: 484
- Avg. Pages per Extent........................: 7.9
- Scan Density [Best Count:Actual Count].......: 41.24% [200:485]
- Logical Scan Fragmentation ..................: 11.03%
- Extent Scan Fragmentation ...................: 0.00%
- Avg. Bytes Free per Page.....................: 1767.7
- Avg. Page Density (full).....................: 78.16%
The internal storage structure of Testchar did not change after update, because at the time of inserting data it stored 100 spaces for the Name column. The number of pages was fixed with inserting. When we update this table no extra space is required to store values as it was already allocated.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)