Msg 8115, Level 16 Arithmetic overflow

In Sql Server, if you try to count more than 2.1 billion rows or sum up values more than that, you will get this message: Msg 8115, Level 16, State 2, Line 1 Arithmetic overflow error converting expression to data type int.

Today I will show you the solution to this problem.

Continue reading Msg 8115, Level 16 Arithmetic overflow

SQL Server 2019 New Feature — Msg 8152, Level 16, State 14 String or binary data would be truncated. Improvement!

There are all kinds of new features in the new version of SQL Server 2019.  One of the ones I am excited about is the additional information you now receive be default when you try to insert data that is too long to fit into an existing field.  In prior versions you would get the message below, but you would have no idea what row or field was causing the issue:

Msg 8152, Level 16, State 14, Line 5 String or binary data would be truncated.

Continue reading SQL Server 2019 New Feature — Msg 8152, Level 16, State 14 String or binary data would be truncated. Improvement!

Insert into Table with an Identity column

Have you ever deleted a row of data and then needed to put it back due to being told it was the wrong row, but the table had an identity column and will not let you insert the row back?  Using the Set Identity_Insert command, you can insert into the table.

Continue reading Insert into Table with an Identity column