Home Web Front-end HTML Tutorial Week 4 Page limit 8060 bytes_html/css_WEB-ITnose

Week 4 Page limit 8060 bytes_html/css_WEB-ITnose

Jun 24, 2016 am 11:45 AM

Congratulations! There are only a few pages left in front of you, and then you can complete the first month of SQL Server Performance Tuning Training. Today I'm going to talk about some of the limitations on the next page and why you'll love them and why you'll hate them.

As you learned in Week 2, a data page is always 8kb in size, and you can only store 8060 bytes on it. Your record size indicates how many records you can store on a page. When you deal with fixed-length data types such as CHAR, INT, DATETIME, etc., you will find that SQL Server has a limit that the record length cannot exceed 8060 bytes (including 7 bytes of internal row overhead).

Page limit? The good side

When your table has fewer than 8 columns, you need to add an additional 7 bytes of internal row overhead (for each record). For every 8 additional columns you add an extra 1 byte, for example, for 17 columns you need 9 btyes of internal row overhead (7 1 1). If you try to create a longer record size, SQL Server will return an error message to you when you execute the CREATE TABLE statement. Let’s take a look at the following table definition:

1 CREATE TABLE TooLargeTable12 (3    Column1 CHAR(5000),4    Column2 CHAR(3000),5    Column3 CHAR(54)6 )7 GO
Copy after login

As you can see, each record requires 8061 bytes (5000 3000 54 7 bytes). So in this case, when you try to create this table, SQL Server will return the following error message.

When you create a table with more than 8 columns, you need to include the 8 bytes of row internal overhead required by SQL Server.

1 CREATE TABLE TooLargeTable22 (3    Column1 CHAR(1000) NOT NULL,   Column2 CHAR(1000) NOT NULL,4    Column3 CHAR(1000) NOT NULL,   Column4 CHAR(1000) NOT NULL,5    Column5 CHAR(1000) NOT NULL,   Column6 CHAR(1000) NOT NULL,6    Column7 CHAR(1000) NOT NULL,   Column8 CHAR(1000) NOT NULL,7    Column9 CHAR(53) NOT NULL8 )9 GO
Copy after login

So here is another illegal table definition (8000 53 8 bytes), and SQL Server will return an error message.

Page limits?? The bad side

In the previous link I have shown you the side of page limits that you like, because when you create such a table, SQL Server will return You got an error message. But page limits also have a nasty side, because SQL Server will allow you to create such a table, and sometimes the INSERT statement will succeed and sometimes it will fail... Let's take a look.

The problem we face here is with variable length data types like VARCHAR. When these columns cannot exist on its own page, SQL Server moves them to row offsets on another page. This is called a Row-Overflow page . SQL Server will leave a 24 bytes long pointer to the row overflow page in the original page.

In some cases when other columns are combined, this pointer will exceed the 8060 bytes limit. Let’s take a look at the following table definition:

1 CREATE TABLE TooLargeTable32 (3    Column1 CHAR(5000),4    Column2 CHAR(3000),5    Column3 CHAR(30),6    Column4 VARCHAR(3000)7 )8 GO
Copy after login

As you can see, here I used the data type of VARCHAR (3000) . You will see that SQL Server will give you a warning message here. This warning indicates that you can create this table, but it may fail when executing the INSERT/UPDATE statement...

The following insert statement in the table will succeed:

1 INSERT INTO TooLargeTable3 VALUES2 (3    REPLICATE('x', 5000),4    REPLICATE('x', 3000),5    REPLICATE('x', 30),6    REPLICATE('x', 19)7 )8 GO
Copy after login

The record size here is 8056 bytes long (5000 3000 30 19 7 bytes). In this case, SQL Server will save the data in column 4 in the main data page. But imagine the following INSERT statement:

1 INSERT INTO TooLargeTable3 VALUES2 (3    REPLICATE('x', 5000),4    REPLICATE('x', 3000),5    REPLICATE('x', 30),6    REPLICATE('x', 3000)7 )8 GO 
Copy after login

In the INSERT statement just now, SQL Server will move the 4th column data to the row-overflow page (row-overflow page), because These 3000 bytes cannot be placed in the main data page. This means that SQL Server will leave a 24bytes long pointer to a different page where the data can be found. But our record size is now 8061 bytes long (5000 3000 30 24 7 bytes).

Duang, your record length exceeds 8060 bytes, and the INSERT statement failed to execute!

These are bad restrictions because they are hidden during database operations. The good thing is that when you define The table structure is visible as shown above. Think about it, what is it?

Summary

When you design your table structure, you have to think about your operations very carefully. When dealing with pages in SQL Server you will encounter many such limitations that only appear after execution. Of course, when SQL Server gives you an error message, you are not allowed to create this table, and the world is basically at peace.

When you receive a warning, almost everyone ignores it without even thinking about it. This is always a bad move, because as you've seen, your INSERT may fail at runtime, and you can expect the problem to occur. I hope you now understand that this performance tuning training is a good low-down and why it is so important to understand the internal structure of data pages!

In the next training I will explain more details about heap tables in SQL Server, and why they are sometimes good (design) and sometimes bad (design). Please stay tuned and enjoy the remaining 7 days!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1672
14
PHP Tutorial
1277
29
C# Tutorial
1257
24
HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML: Is It a Programming Language or Something Else? HTML: Is It a Programming Language or Something Else? Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

Beyond HTML: Essential Technologies for Web Development Beyond HTML: Essential Technologies for Web Development Apr 26, 2025 am 12:04 AM

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

What is the difference between <strong>, <b> tags and <em>, <i> tags? What is the difference between <strong>, <b> tags and <em>, <i> tags? Apr 28, 2025 pm 05:42 PM

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

See all articles