Share via

Does input parameter type matter?

Naomi Nosonovsky 8,906 Reputation points
2020-11-24T15:04:30.68+00:00

We have a very simple stored procedure that is executed very often as it writes to a simple audit table. One of the columns in that table defined as tinyint. However, parameter to the stored procedure defined as int. I'm wondering if there is any conversion done during the INSERT command and does this even matter that the parameter type doesn't match the column's type on the INSERT command?

Thanks in advance.

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

0 comments No comments

Answer accepted by question author

David Browne - msft 3,856 Reputation points
2020-11-24T18:07:19.523+00:00

On INSERT this won't matter, as the INT will be implicitly converted to TINYINT. On INSERT the parameter type is always converted to the column type, and the implicit conversion itself is very, very inexpensive.

On SELECT when passing the parameter in the WHERE clause, this matters much more as INT has a higher data type precedence than TINYINT, and will cause the column values to be converted to the parameter type, instead of vice-versa, requiring a conversion for each row and preventing index use.

Was this answer helpful?


3 additional answers

Sort by: Most helpful
  1. Guoxiong 8,221 Reputation points
    2020-11-24T17:58:00.21+00:00

    Converting int to tinyint may not affect the performance. But I would suggest to change the data type of the parameter to tinyint. This way would avoid a run time error if that parameter value is greater than 255.

    Was this answer helpful?

    0 comments No comments

  2. Naomi Nosonovsky 8,906 Reputation points
    2020-11-24T17:36:54.113+00:00

    My question is more performance wise oriented. Does the conversion happen behind the scenes and would it make sense to change parameter type (since this procedure is one of the most executed procedures) or it should not matter?

    Was this answer helpful?


  3. Anonymous
    2020-11-24T15:15:13.1+00:00

    Shouldn't really be a problem until / unless the input value exceeded the bounds of the tinyint column

    --please don't forget to Accept as answer if the reply is helpful--

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.