Microsoft KB Archive/827968

= How to estimate the size of a SQL Server CE or SQL Server 2005 Mobile Edition database =

Article ID: 827968

Article Last Modified on 11/20/2007

-

APPLIES TO


 * Microsoft SQL Server 2000 Windows CE Edition 2.0
 * Microsoft SQL Server 2000 Windows CE Edition 1.1
 * Microsoft Encarta Interactive World Atlas 2001
 * Microsoft SQL Server 2005 Compact Edition

-



SUMMARY
This article describes how to estimate the size of a Microsoft SQL Server 2000 Windows CE Edition database or a Microsoft SQL Server 2005 Mobile Edition database. However, this estimate cannot be determined with real accuracy because of the following reasons:
 * The size of the system table may vary, especially when you use SQL Server CE or SQL Server 2005 Mobile Edition synchronization.
 * The estimate does not account for the space that is taken by indexes.
 * For simplicity, the estimate assumes contiguous row storage (that is, after you compact a database). SQL Server CE or SQL Server 2005 Mobile Edition stores rows on 4 KB pages, and it does not split rows across pages, except for text and ntext data types. Because all the pages are not always filled, some unused space exists on individual pages. Also, if a page has rows and some of those rows are deleted, the space for the deleted rows is not reclaimed until the database is compacted. If all the rows in a page are deleted, the page is reclaimed later.
 * The length of some data types may vary depending on the data that they contain, including the nvarchar and ntext data types. When you estimate the size of a column, the estimate is based on the maximum column size, not on the actual size of the data that is stored in the column. For example, if a column has a data type of nvarchar(50) and has a value of &quot;Hello,&quot; the actual size of the column is 5 bytes, but the estimated size is 50 bytes.



MORE INFORMATION
When you estimate the size of a table or of a database, consider the following information:
 * Each row in the table has an overhead of 6 bytes.
 * Each column in the table has an overhead of 1 byte, plus 1 byte for every 256 bytes of row storage.
 * Fixed-length data types have an overhead of 1 byte for each column, and the overhead is rounded to the next higher byte.
 * Zero-length string columns occupy 1 byte in the row.
 * SQL Server CE or SQL Server 2005 Mobile Edition stores data in Unicode format. If the collation string that is used to create the database is a double-byte character set (DBCS) language (such as kanji), the size of the string columns is doubled because each byte is stored as 2 bytes. If the collation string that is used to create the database is a single-byte character set (SBCS) language (such as English), SQL Server CE removes the leading unused byte. As a result, SBCS collation strings are estimated as 1 byte for each character.
 * If the SQL Server CE tables or the SQL Server 2005 Mobile Edition tables are used in merge replication, there are three system columns for each table.
 * If the SQL Server CE tables or the SQL Server 2005 Mobile Edition tables participate in Remote Data Access (RDA), there are 2 system columns for each table.

The following table describes the data types in SQL Server CE and the storage size for each data type.

If you are using SQL Server 2005 Mobile Edition
For more infomation about the data types in SQL Server 2005 Mobile Edition, see the &quot;Data Types&quot; topic in SQL Server 2005 Books Online.

In the following scenarios, the size of a table is estimated depending on the data type of the column, the number of rows, the collation, and the type of synchronization.

Scenario 1
In this scenario, the size of the myTableA1 table is estimated. The table has the following characteristics:
 * The myTableA1 table has 10,000 rows.
 * The myTableA1 table is created with the default English collation, and the table does not use any form of SQL Server CE synchronization.

The following table describes the type of each column in the myTableA1 table and the number of bytes that are occupied by each column.

The total size of each row in the myTableA1 table is 76 (66+10) bytes. Because the table has 10,000 rows, the total size of the myTableA1 table is 760,000 bytes (76*10,000). Because the calculation takes into account the maximum size of the nvarchar data type, this is only an estimate of the table size. The actual size of the table may vary depending on the value that is stored in the nvarchar data type.

Note If the data values in a column are expected to vary considerably, you must use the nvarchar data type to reduce the database size.

Scenario 2
In this scenario, the size of the myTableA2 table is estimated. The table has the following characteristics:
 * The myTableA2 table has 91 rows.
 * The myTableA2 table is created with the default English collation, and the table is used in merge replication.

The following table describes the type of each column in the myTableA2 table and the number of bytes that are occupied by each column.

The total size of each row of the myTableA2 table is 333 (312+21) bytes. Because the table has 91 rows, the total size of the myTableA2 table is 30,303 bytes. Because the actual size of the string column values is not known, this size is only an estimate.

Scenario 3
In this scenario, the size of the myTableA3 table is estimated. The table participates in RDA and has the following characteristics:
 * The myTableA3 table has 91 rows.
 * The myTableA3 table is created with the default English collation, and this table has the primary key columns because they are used as part of one of the system columns that is tracked for RDA.

The following table describes the type of each column in the myTableA3 table and the number of bytes that are occupied by each column.

If the primary key is changed, the total size of the table is 345 (325+20) bytes for each row. Because the myTableA3 table has 91 rows, the size of the table is 31,395 bytes. If the primary key is not changed, the total size of the table is 293 (273+20) bytes for each row. Because the myTableA3 table has 91 rows, the size of the table is 26,663 bytes. Because the actual size of the string column values is not known, this is only an estimate.

Keywords: kbtable kbdatabase kbinfo KB827968

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.