0

I found that if a column data type is set as varchar(max) in a table will affect the performance by the following

  1. large space will be occupied
  2. indexing is not possible

But does it affect, when I use a query like Cast(column name as varchar(max)) in a column which does not have large values?

I don't seem to find any delay while using a query like above.

Note: I don't have permission to see the column size.

Raju Ahmed
  • 1,282
  • 5
  • 15
  • 24
  • Why are you converting the column to a `varchar(MAX)` in the first place? Where are you converting it? – Thom A Dec 07 '21 at 11:55
  • Why do you need to change the size of the column in the select query? In general, yes it will be marginally slower as SQL Server has to perform data type conversion, but in select queries, I believe, the cost is trivial. The question is why do you need to do it? – Alex Dec 07 '21 at 11:56
  • I don't know the size of column and data size is variable . So I would like to query like this. I will use this only to select the data and visualise it, i.e I'm not going to store it@Alex @Larnu – Praveenkumar Dec 07 '21 at 12:05
  • *"data size is variable"* That's the point of a `varchar` the `var` stands for *variable*. But casting the value to a `MAX` doesn't help if it's already suffered truncation. – Thom A Dec 07 '21 at 12:07
  • _Note:I don't have permission to see the column size._ Then ASK people that either know or can give you some level of minimal permission to do your work. In fact, ASK your coworkers questions like this and learn from each other. You are supposed to work as a **team**, that doesn't happen without communication. – SMor Dec 07 '21 at 12:23
  • You should be able to use [`sp_describe_first_result_set`](https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-describe-first-result-set-transact-sql?view=sql-server-ver15) to get column sizes of an SQL query. – Alex Dec 07 '21 at 13:06
  • i used to query with n number of tables in multiple databases. I can't be asking column size for all column right? . So it would be really helpful if anyone tell me whether querying like this will slower the execution time. Thanks in advance!! – Praveenkumar Dec 07 '21 at 13:10

0 Answers0