Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


The storage of VARCHAR(MAX) when null


The storage of VARCHAR(MAX) when null

Author
Message
Ove.Kernell
Ove.Kernell
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 34
Hi all,
If I have a table
CREATE TABLE [dbo].[logg](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Details] [varchar](MAX) NULL)

insert logg (Details) values('')
insert logg (Details) values(null)

Will both statements above access only a single page (as it fits into one page)
or does the VARCHAR(MAX) always put its data on a separate page.
If so, is the null insert treated differently from the '' insert?

Regards Ove
Eirikur Eiriksson
Eirikur Eiriksson
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8303 Visits: 18199
Ove.Kernell (5/7/2014)
Hi all,
If I have a table
CREATE TABLE [dbo].[logg](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Details] [varchar](MAX) NULL)

insert logg (Details) values('')
insert logg (Details) values(null)

Will both statements above access only a single page (as it fits into one page)
or does the VARCHAR(MAX) always put its data on a separate page.
If so, is the null insert treated differently from the '' insert?

Regards Ove


If it fits on a single page, as this does, then yes.
You can poke around with a query like the one belowCool
ELECT 
object_name(sp.object_id) AS oname
,ps.used_page_count
,ps.lob_used_page_count
,ps.in_row_data_page_count
,ps.row_overflow_used_page_count
FROM sys.dm_db_partition_stats ps
INNER JOIN sys.partitions sp
ON ps.partition_id = sp.partition_id


ScottPletcher
ScottPletcher
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4407 Visits: 6833
By default, yes, they will be stored in the same page.

Someone can, however, override SQL's default behavior, table by table, via "EXEC sp_tableoption" and force SQL to store all LOBs outside of the row.

It's not likely that's been done, but it is possible.

SQL DBA,SQL Server MVP('07, '08, '09)

Prosecutor James Blackburn, in closing argument in the "Fatal Vision" murders trial: "If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search