0

i am working on existing software(SQL,C#) for increase its efficiency.in this project every where varchar(max) is used where string required.I want to convert varchar(Max) into varchar(N).for this purpose i read many article which compares varchar(max) Vs varchar(N)-it is clear that response time of varchar(N) is grater than Varchar(Max).But my question about storage comparison Varchar(Max) Vs Varchar(N)-e.g. if i insert "Hello", is storage same for both datatypes varchar(Max) and varchar(100)? if not then how much difference in both cases?

Ubaid
  • 77
  • 10
  • Take help from this link- https://stackoverflow.com/questions/20229441/implications-of-nvarchar-50-vs-nvarchar-max – mkRabbani Aug 21 '19 at 07:41
  • Storage of an `(n)varchar(MAX)` is different to an `(n)varchar(x)`. a `MAX` data type will often be in a different storage location to the table (not in the same pages). The values will looked up when the value is needed. – Thom A Aug 21 '19 at 07:52
  • @Larnu thank you...we can says varchar(MAX) take much space than varchar(N)..if text length is fixed? – Ubaid Aug 21 '19 at 07:55
  • *"if text length is fixed"* No, it's an **var**char, not a char. the var is an abbreviation of varying; as in the value has a varying length. If you're working with fixed length strings, you'll want a `char`. – Thom A Aug 21 '19 at 08:01
  • Possible duplicate of [Implications of nvarchar (50) vs nvarchar (max)](https://stackoverflow.com/questions/20229441/implications-of-nvarchar-50-vs-nvarchar-max) – Amira Bedhiafi Aug 21 '19 at 08:02
  • @Larnu i means taht if i insert anyone "hello" ,"helloworld","hello everyone" then is storage same for both datatypes?. – Ubaid Aug 21 '19 at 08:06
  • Have a look here: https://stackoverflow.com/a/5705203/3484879. Using your search engine will likely find a lot of the answers you're looking for here. – Thom A Aug 21 '19 at 08:09

1 Answers1

0

Varchar(MAX) & Varchar(n) reserve fix space for same text store in Column. I have two table tblMaxData & tblNData and both table have single column with VARCGAR(MAX) & VARCHAR(N). Column have 'Hello' Value in Both Table. After then i was checked space , both column has same occupied Space. enter image description here

enter image description here

hardikpatel
  • 300
  • 1
  • 5