Calculating total “on row” bytes for each row … the easy waySQL Database size doesn't match with the...
Why is airport car rental so cheap
Does the Resurrection spell consume material components if the target isn’t willing to be resurrected?
Can I do anything else with aspersions other than cast them?
The Longest Chess Game
Can a planet be tidally unlocked?
What did Putin say about a US deep state in his state-of-the-nation speech; what has he said in the past?
Why is quixotic not Quixotic (a proper adjective)?
How do I write a maintainable, fast, compile-time bit-mask in C++?
Smallest possible mole
Why write a book when there's a movie in my head?
Does the Holy Ark weigh 4 tons?
Why is Shelob considered evil?
A cancellation property for permutations
Are encryption algorithms with fixed-point free permutations inherently flawed?
How can a kingdom keep the secret of a missing monarch from the public?
Is it ethical to apply for a job on someone's behalf?
Why would you use 2 alternate layout buttons instead of 1, when only one can be selected at once
How to modify 'inter arma enim silent leges' to mean 'in a time of crisis, the law falls silent'?
Coworker is trying to get me to sign his petition to run for office. How to decline politely?
Can I legally make a website about boycotting a certain company?
How can guns be countered by melee combat without raw-ability or exceptional explanations?
Why does this quiz question say that protons and electrons do not combine to form neutrons?
SQL Server 2017 crashes when backing up because filepath is wrong
Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded
Calculating total “on row” bytes for each row … the easy way
SQL Database size doesn't match with the total table sizes in the databaseDo you know an easy way to generate one record for each hour of the past 12 hours?Calculate number for each rowRunning total to the previous rowChoosing the right storage block size for sql serverCalculating Running Total After ResetSQL Server 2016 Maximum Bytes/RowWhat's the best way to iterate through the table to update a column in each row?sql server getting total for each groupSQL Server chooses Nested Loop join with dimensional table and make seek for each row
We want to calculate the total "on row" storage bytes for each row in the table. As we understand it, we must add up the DATALENGTH() of each column while also accounting for NULLs and things like VARCHAR(MAX) which only have a 24-byte pointer "on row". We are aware there is also some overhead for each row which is not accounted for in the query below.
SELECT ROW_ID,
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL1','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL1), 1)
END
+
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL2','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL2), 1)
END
+
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL3','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL3), 1)
END
+
...
...
AS ROW_SIZE
FROM EXAMPLE_TABLE
ORDER BY ROW_SIZE DESC
;
What a beast! And it's only an approximation.
Then we discovered
DBCC SHOWCONTIG ('EXAMPLE_TABLE') WITH TABLERESULTS
which returns MaximumRecordSize. This reveals that there is already an algorithm buried somewhere within SQL Server which is capable of calculating the exact size of a row.
How can we access that algorithm directly?
sql-server sql-server-2017 storage dbcc size
add a comment |
We want to calculate the total "on row" storage bytes for each row in the table. As we understand it, we must add up the DATALENGTH() of each column while also accounting for NULLs and things like VARCHAR(MAX) which only have a 24-byte pointer "on row". We are aware there is also some overhead for each row which is not accounted for in the query below.
SELECT ROW_ID,
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL1','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL1), 1)
END
+
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL2','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL2), 1)
END
+
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL3','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL3), 1)
END
+
...
...
AS ROW_SIZE
FROM EXAMPLE_TABLE
ORDER BY ROW_SIZE DESC
;
What a beast! And it's only an approximation.
Then we discovered
DBCC SHOWCONTIG ('EXAMPLE_TABLE') WITH TABLERESULTS
which returns MaximumRecordSize. This reveals that there is already an algorithm buried somewhere within SQL Server which is capable of calculating the exact size of a row.
How can we access that algorithm directly?
sql-server sql-server-2017 storage dbcc size
3
sys.dm_db_index_physical_stats is probably better to try working off of, especially since that DBCC command is deprecated.
– LowlyDBA
1 hour ago
add a comment |
We want to calculate the total "on row" storage bytes for each row in the table. As we understand it, we must add up the DATALENGTH() of each column while also accounting for NULLs and things like VARCHAR(MAX) which only have a 24-byte pointer "on row". We are aware there is also some overhead for each row which is not accounted for in the query below.
SELECT ROW_ID,
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL1','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL1), 1)
END
+
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL2','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL2), 1)
END
+
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL3','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL3), 1)
END
+
...
...
AS ROW_SIZE
FROM EXAMPLE_TABLE
ORDER BY ROW_SIZE DESC
;
What a beast! And it's only an approximation.
Then we discovered
DBCC SHOWCONTIG ('EXAMPLE_TABLE') WITH TABLERESULTS
which returns MaximumRecordSize. This reveals that there is already an algorithm buried somewhere within SQL Server which is capable of calculating the exact size of a row.
How can we access that algorithm directly?
sql-server sql-server-2017 storage dbcc size
We want to calculate the total "on row" storage bytes for each row in the table. As we understand it, we must add up the DATALENGTH() of each column while also accounting for NULLs and things like VARCHAR(MAX) which only have a 24-byte pointer "on row". We are aware there is also some overhead for each row which is not accounted for in the query below.
SELECT ROW_ID,
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL1','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL1), 1)
END
+
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL2','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL2), 1)
END
+
CASE
WHEN COLUMNPROPERTY(OBJECT_ID('EXAMPLE_TABLE'),'COL3','PRECISION') = -1 THEN 24
ELSE ISNULL(DATALENGTH(COL3), 1)
END
+
...
...
AS ROW_SIZE
FROM EXAMPLE_TABLE
ORDER BY ROW_SIZE DESC
;
What a beast! And it's only an approximation.
Then we discovered
DBCC SHOWCONTIG ('EXAMPLE_TABLE') WITH TABLERESULTS
which returns MaximumRecordSize. This reveals that there is already an algorithm buried somewhere within SQL Server which is capable of calculating the exact size of a row.
How can we access that algorithm directly?
sql-server sql-server-2017 storage dbcc size
sql-server sql-server-2017 storage dbcc size
asked 1 hour ago
UnLogicGuysUnLogicGuys
16218
16218
3
sys.dm_db_index_physical_stats is probably better to try working off of, especially since that DBCC command is deprecated.
– LowlyDBA
1 hour ago
add a comment |
3
sys.dm_db_index_physical_stats is probably better to try working off of, especially since that DBCC command is deprecated.
– LowlyDBA
1 hour ago
3
3
sys.dm_db_index_physical_stats is probably better to try working off of, especially since that DBCC command is deprecated.
– LowlyDBA
1 hour ago
sys.dm_db_index_physical_stats is probably better to try working off of, especially since that DBCC command is deprecated.
– LowlyDBA
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
How can we access that algorithm directly?
In so far as the answer to this question, specifically, you can't access it directly. There is nothing where you can say SELECT GetMeMaxRowSize(MyTable, MyPartition, MyIndex).
However, as LowlyDBA has pointed out, you can use sys.dm_db_index_physical_stats to give you more information than ShowContig. The quite interesting thing is that if you run DBCC SHOWCONTIG(), capturing deprecated information, you should see a message to use the aforementioned DMV in place of the ShowContig command.
That's neat! Any idea if we'll see more explicit nudging around deprecated features, like said message, going forwards?
– LowlyDBA
59 mins ago
@LowlyDBA Unfortunately I do not, but we try to point people in the right direction :) If you think this should be updated or put anywhere in Docs, please let me know.
– Sean Gallardy
49 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230422%2fcalculating-total-on-row-bytes-for-each-row-the-easy-way%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
How can we access that algorithm directly?
In so far as the answer to this question, specifically, you can't access it directly. There is nothing where you can say SELECT GetMeMaxRowSize(MyTable, MyPartition, MyIndex).
However, as LowlyDBA has pointed out, you can use sys.dm_db_index_physical_stats to give you more information than ShowContig. The quite interesting thing is that if you run DBCC SHOWCONTIG(), capturing deprecated information, you should see a message to use the aforementioned DMV in place of the ShowContig command.
That's neat! Any idea if we'll see more explicit nudging around deprecated features, like said message, going forwards?
– LowlyDBA
59 mins ago
@LowlyDBA Unfortunately I do not, but we try to point people in the right direction :) If you think this should be updated or put anywhere in Docs, please let me know.
– Sean Gallardy
49 mins ago
add a comment |
How can we access that algorithm directly?
In so far as the answer to this question, specifically, you can't access it directly. There is nothing where you can say SELECT GetMeMaxRowSize(MyTable, MyPartition, MyIndex).
However, as LowlyDBA has pointed out, you can use sys.dm_db_index_physical_stats to give you more information than ShowContig. The quite interesting thing is that if you run DBCC SHOWCONTIG(), capturing deprecated information, you should see a message to use the aforementioned DMV in place of the ShowContig command.
That's neat! Any idea if we'll see more explicit nudging around deprecated features, like said message, going forwards?
– LowlyDBA
59 mins ago
@LowlyDBA Unfortunately I do not, but we try to point people in the right direction :) If you think this should be updated or put anywhere in Docs, please let me know.
– Sean Gallardy
49 mins ago
add a comment |
How can we access that algorithm directly?
In so far as the answer to this question, specifically, you can't access it directly. There is nothing where you can say SELECT GetMeMaxRowSize(MyTable, MyPartition, MyIndex).
However, as LowlyDBA has pointed out, you can use sys.dm_db_index_physical_stats to give you more information than ShowContig. The quite interesting thing is that if you run DBCC SHOWCONTIG(), capturing deprecated information, you should see a message to use the aforementioned DMV in place of the ShowContig command.
How can we access that algorithm directly?
In so far as the answer to this question, specifically, you can't access it directly. There is nothing where you can say SELECT GetMeMaxRowSize(MyTable, MyPartition, MyIndex).
However, as LowlyDBA has pointed out, you can use sys.dm_db_index_physical_stats to give you more information than ShowContig. The quite interesting thing is that if you run DBCC SHOWCONTIG(), capturing deprecated information, you should see a message to use the aforementioned DMV in place of the ShowContig command.
answered 1 hour ago
Sean GallardySean Gallardy
16.2k22649
16.2k22649
That's neat! Any idea if we'll see more explicit nudging around deprecated features, like said message, going forwards?
– LowlyDBA
59 mins ago
@LowlyDBA Unfortunately I do not, but we try to point people in the right direction :) If you think this should be updated or put anywhere in Docs, please let me know.
– Sean Gallardy
49 mins ago
add a comment |
That's neat! Any idea if we'll see more explicit nudging around deprecated features, like said message, going forwards?
– LowlyDBA
59 mins ago
@LowlyDBA Unfortunately I do not, but we try to point people in the right direction :) If you think this should be updated or put anywhere in Docs, please let me know.
– Sean Gallardy
49 mins ago
That's neat! Any idea if we'll see more explicit nudging around deprecated features, like said message, going forwards?
– LowlyDBA
59 mins ago
That's neat! Any idea if we'll see more explicit nudging around deprecated features, like said message, going forwards?
– LowlyDBA
59 mins ago
@LowlyDBA Unfortunately I do not, but we try to point people in the right direction :) If you think this should be updated or put anywhere in Docs, please let me know.
– Sean Gallardy
49 mins ago
@LowlyDBA Unfortunately I do not, but we try to point people in the right direction :) If you think this should be updated or put anywhere in Docs, please let me know.
– Sean Gallardy
49 mins ago
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230422%2fcalculating-total-on-row-bytes-for-each-row-the-easy-way%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
sys.dm_db_index_physical_stats is probably better to try working off of, especially since that DBCC command is deprecated.
– LowlyDBA
1 hour ago