I am trying to understand how SQL selects new data pages when we insert some new records into a table.
I created a sample Employee table in a new database using
Create Database TestDb GO Use TestDb GO Create table Employee ( EmployeeName char(1000)) GO Insert into Employee values ('Employee1') DBCC IND('TestDb','dbo.Employee',-1)
After starting DBCC, I saw 2 pages. One of them is the IAM page (PageType = 10), and the other is the Data page (PageType = 1), which contains the actual data.
Later I checked the actual contents of the data page using the DBCC page
DBCC TRACEON(3604) DBCC PAGE('TestDb',1,298,3)
I saw how SQL calculates the number of bytes of m_freecnt -
= 1007 bytes RecordSize + 96 bytes Header + offset 2 bytes = 1105 bytes
i.e. 8K Page = 8192 bytes = 8192 - 1105 = 7087 bytes for free.

Now I continue to add records to this table to understand how many records will be on this page, and when SQL selects a new page in which m_FreeCnt will be taken into account.
(Record size = 1007 and byte offset = 2)
The second entry is added -
Insert into Employee values ('Employee2') GO
Last free account = 7087, i.e. 7087 - 1007 - 2 = 6087 => m_FreeCnt = 6078
Insert into Employee values ('Employee3') GO
Last free account = 6078, i.e. 6078-1007-2 = 5069 => m_FreeCnt = 5069
Insert into Employee values ('Employee4') GO
Last free account = 5069, i.e. 5069 - 1007 - 2 = 4060 => m_FreeCnt = 4060
Insert into Employee values ('Employee5') GO
Last free account = 4060, i.e. 4060 - 1007 - 2 = 3051 => m_FreeCnt = 3051
Insert into Employee values ('Employee6') GO
Last free account = 3051, i.e. 3051 - 1007 - 2 = 2042 => m_FreeCnt = 2042
Insert into Employee values ('Employee7') GO
Last free account = 2042, i.e. 2042 - 1007 - 2 = 1033 => m_FreeCnt = 1033
So far, everything is working fine. Now 1033 bytes are left on this data page. As soon as I add the 8th record, ideally it should not create another page, because the number of free bytes is 1033 , which is enough to accommodate the 8th record (1009 bytes are enough). However, SQL creates a new date page to save this eighth record.
I inserted the 8th record and ran DBCC IND to check this -
Insert into Employee values ('Employee7') GO DBCC IND('TestDb','dbo.Employee',-1)
Now he has created a new data page with PageNumber = 300.
I did not understand this part. Regardless of whether SQL stores reserved bytes except [header (96) + Data part + offset per page 2 bytes] this?
Can you try the query and let me know if I'm missing something here? Or should we not worry about this SQL memory data?
Thanks.