T-SQL Vocab 101: What does Scalar mean?
This is the story of my first encounter with anything “scalar” in regards to T-SQL. I was just starting to use variables. I tried something similar to this:
Set @var = 1;
Here is a re-creation of the error:
From the error, I could tell I was trying to set a variable I didn’t declare, but I wondered “hmm what does scalar mean?” It seemed overly mathematical and a little scary. I searched an online dictionary: “A quantity having only magnitude, not direction”. I was more confused. I went to youtube and watched some math-related videos. I did eventually get a good grip on scalar quantities and vector quantities (math is fun). However, the question was still there, how does this relate to a variable in T-SQL?
A little research goes a long way
The real question was: What does Scalar mean in the context of computer science and more specifically T-SQL? After some research, I found that the origins of the word scalar as it relates to computer science come from the scalar processor. A processor that can only handle one value at a time. For more on the scalar processor:
https://en.wikipedia.org/wiki/Scalar_processor
So what does Scalar mean?
A scalar variable is a variable that can only hold a single value, a scalar expression evaluates to a single value, and a scalar function returns a single value. Scalar is an adjective used to indicate that the variable/expression/function either holds or returns a single value. When I see scalar, I think single value.