473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Heap table: why 454 rows of two INT columns use 2 data pages?

IF (SELECT OBJECT_ID('t1')) IS NOT NULL
DROP TABLE t1
GO

CREATE TABLE t1 (c1 INT, c2 INT)
DECLARE @n INT
SET @n = 1
WHILE @n <= 454
BEGIN
INSERT INTO t1 VALUES (@n, @n)
SET @n = @n + 1
END

SELECT name, indid, CASE indid
WHEN 0 THEN 'Table'
WHEN 1 THEN 'Clustered Index'
ELSE 'Nonclustered Index'
END AS Type,
dpages, rowcnt
FROM sysindexes
WHERE id = OBJECT_ID('T1')
name indid Type dpages rowcnt
---- ----- ---- ------ ------
NULL 0 Table 2 454
I have a table containing 454 rows of two columns
of type INT with each being 4 bytes

c1 int = 4 bytes
+
c2 int = 4 bytes
=
8 bytes per row

If I entered 454 rows : 454 * 8 = 3,632 bytes

each SQL Page is 8KB = 8 * 1024 bytes
= 8,192 bytes

a data page header takes the first 96 bytes
leaving 8096 bytes for data and row offsets.

Each record uses a row offset at the end of the page
consisting of 2 bytes. 454 * 2 = 908 bytes.

8096 - 3632 - 908 = 3,556 bytes. Should this be
free data bytes?

For a heap table, does SQL add an internal uniqueidentifier
column also? or my question is when does SQL add
a uniqueidentifier? I am reading Inside SQL 2000 and
trying to understand a few things.
A uniqueidentifier of 4 bytes gets added when a clustered index
exists but it is NOT a UNIQUE clustered index. AND only
if duplicate record is added those two records only get
a uniqueidentifier value.

But in my example it's a heap table with no indexes. Even
on a heap table with no indexes a ROWID or Uniqueidentifier
get added? Based on the INSERT statement above all
values are unique.

So what am I missing to understand why 453 rows
make one data page to be used whereas 454 rows
make two data pages to be used?
Thank you
Mar 2 '07 #1
1 1565
serge (se****@nospam.ehmail.com) writes:
If I entered 454 rows : 454 * 8 = 3,632 bytes

each SQL Page is 8KB = 8 * 1024 bytes
= 8,192 bytes

a data page header takes the first 96 bytes
leaving 8096 bytes for data and row offsets.

Each record uses a row offset at the end of the page
consisting of 2 bytes. 454 * 2 = 908 bytes.

8096 - 3632 - 908 = 3,556 bytes. Should this be
free data bytes?
No. You are forgetting that there is fixed overhead of each row of at
least nine bytes. See page 253 in "Inside SQL Server 2000".

454*17 is still only 7718, but I believe that there is some margin
left for the page to grow.
A uniqueidentifier of 4 bytes gets added when a clustered index
exists but it is NOT a UNIQUE clustered index. AND only
if duplicate record is added those two records only get
a uniqueidentifier value.
Actually it's called a "uniquifier". I like to make this distinction,
since uniqueidentifier is a data type which is 16 bytes wide.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Mar 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike, plane, tractor etc etc For the table design I am...
61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
7
by: Bing Wu | last post by:
Hi Folks, I have a very large table containing 170 million rows of coordinats: CREATE TABLE "DB2ADMIN"."COORDINATE" ( "FID" INTEGER NOT NULL , "AID" INTEGER NOT NULL , "X" REAL NOT NULL ,...
16
by: JCauble | last post by:
We have a large Asp.net application that is currently crashing our production servers. What we are seeing is the aspnet_wp eat up a bunch of memory and then stop unexpectedly. Does not recycle. ...
1
by: kingster | last post by:
Hi, I have a regular dataset and all i want to do is make a pivot table display in a browser with the datasource of the pivot table to be this dataset and then the end-user will be able to do...
4
by: fmatamoros | last post by:
I sometimes get the following error from an update statement in a stored procedure: Transaction (Process ID 62) was deadlocked on thread | communication buffer resources with another process and...
117
by: phil-news-nospam | last post by:
Is there really any advantage to using DIV elements with float style properies, vs. the old method of TABLE and TR and TD? I'm finding that by using DIV, it still involves the same number of...
5
by: Konstantin Andreev | last post by:
Recently I became interested, - Are the data, bulk loaded in the table with LOAD utility, consume the same disk space as loaded with IMPORT utility? The answer turned out to be NOT ! Here is a...
4
by: Hemant Shah | last post by:
Folks, Our client has a program that browses whole table from begining to end. The table has 1 million rows in it. REORGCHK does not show any problems. It has unique index defined on KEY0...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.