Tuesday, February 14, 2012

DT_I8 versus DT_UI8

Can some one tell me in basic terms the difference between a signed and unsigned integer? When would you decided to use one over the other? I'm looking for it more in layman terms than a technical bit level discussion.Unsigned integers are >= 0 (Just as they say, they are unsigned, so negative numbers can't be stored)|||

So.... is it a true statement to say...

Since an unsigned integer can not be negative, if you know you will have positive integers you should use an unsigned data type. Additionaly, because no "sign" information is stored it can hold a larger number?

Thanks!

|||Yes.|||

1Dave wrote:

So.... is it a true statement to say...

Since an unsigned integer can not be negative, if you know you will have positive integers you should use an unsigned data type. Additionaly, because no "sign" information is stored it can hold a larger number?

Thanks!

Correct. If you know you will always be working with positive integers, then yes, it would be best to use an unsigned integer data type. UIs can hold a "larger" number, but not more numbers -- the storage is the same, but whereas the SIs can hold negative values, UIs simply allow the positive integers to be just that much greater.

DT_I2: -32768 to 32768
DT_UI2: 0 to 65535|||Thanks...|||I also just want to comment, and perhaps someone else can chime in here, but there is no such thing as an unsigned integer type in SQL Server. There is a tinyint (0-255), but all of the other integer types in SQL Server are signed. So using an UI in SSIS and mapping to a SQL Server integer data type (smallint, int, bigint) will undoubtedly cause overflow errors.|||

Just subtract 2,147,483,647 from your UI before inserting it into SQL Server

This actually has caused a few issues in some of the larger warehouses I've worked on. We used an int for a key in a fact that was supposed to be low volume, but due to some business changes, it had to handle a much larger volume of inserts than was anticipated. If we'd had an unsigned int, it would have scaled to the new volume without any changes. Since it wasn't, we had to decide between renumbering our keys (starting from -2,147,483,648), or switching to a bigint (twice the storage).

|||Right, but SQL Server doesn't handle unsigned integers, so really your only options are int, smallint, or bigint.

So, really, I question the value of using UIs in SSIS when your destination is SQL Server.

No comments:

Post a Comment