We help IT Professionals succeed at work.

binary data datatype

We want to serialize some of our c# classes into a database column.  We are going to use binary serialization.  
What would be the best datatype to store the binary data?  Should we use varbinary(max)?  The classes are not very large and when serializing to the file system they are about 7Kb.
Any suggestions?

CREATE TABLE [dbo].[ClassTable](
      [ID] [int] NOT NULL,
      [ClassData] [varbinary](max) NOT NULL,
 CONSTRAINT [PK_ClassTable] PRIMARY KEY CLUSTERED
(
      [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
Comment
Watch Question

Software Engineer
CERTIFIED EXPERT
Commented:
varbinary(max) is your best bet, since you don't know before hand what size you would need in the future

Author

Commented:
now what if we need to store it using text (XML), would varchar(max) be the best bet too?

Commented:
If you only want to use it trough your C# it don't makes a lot of difference.

There is also the XML-datatype, but that will be slower in performance.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.