Why not use varchar(max)?

后端 未结 8 2000
广开言路
广开言路 2020-12-05 17:03

I\'m a bit old school when it comes to database design, so I\'m totally for using the correct data sizes in columns. However, when reviewing a database for a friend, I notic

相关标签:
8条回答
  • 2020-12-05 17:39

    There is a blog post about why not to use varchar max here

    Edit

    The basic difference is where the data is stored. A SQL Data row has a max size of 8000 bytes (or was it 8K). Then a 2GB varchar(max) cannot be stored in the data row. SQL Server stores it "Out of row".

    Therefore you could get a performance hit since the data will not be in the same place on disk, see: http://msdn.microsoft.com/en-us/library/ms189087.aspx

    0 讨论(0)
  • 2020-12-05 17:42

    If you are working in an OLTP environment, you are all about the performance. From overhead and tuning concerns to indexing limitations and query bottlenecks. Using a varcahr(max) or any other LOB type will most likely contravene most design best practices, so unless there is a specific business need that cannot be handled through the use of some other typing mechanism and only a varchar(max) will fit the bill then why subject your system and applications to the kind of overhead and performance issues inherent in one of the LOB datatypes?

    If on the other hand you are working in an OLAP environment or in a Star Schema DW environment with Dimension tables with descriptors fields that naturally need to be verbose then a varchar(max), as long as you are not adding that to an index, may be useful. Still I would recommend even then to use a char(x) varchar(x) As it is always a best practice to only use those resources you absolutely must have to get the job done.

    0 讨论(0)
提交回复
热议问题