SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Integer datatypes in SQlserver


Integer datatypes in SQlserver

Author
Message
newbieuser
newbieuser
SSC Eights!
SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)

Group: General Forum Members
Points: 841 Visits: 915
Hi all, I am trying to look up on the size differences between int, bigint and small int. I mostly work with Oracle and i am trying to compare the width of a column between Oracle and SQlserver on how much width the column would need.

Please help. Thanks.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87291 Visits: 45272
Smallint is 2 bytes and stores values between -32768 and 32767
Int is 4 bytes and stores values betweeen -2,147,483,648 and 2,147,483,647
bigint is 8 bytes and stores values between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


newbieuser
newbieuser
SSC Eights!
SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)

Group: General Forum Members
Points: 841 Visits: 915
Thanks. But application people want to know more about the width rather than the storage size. Like in Oracle we say number(38), it can hold 38 digits.

Thank you
RBarryYoung
RBarryYoung
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14740 Visits: 9518
psangeetha (10/14/2008)
Thanks. But application people want to know more about the width rather than the storage size. Like in Oracle we say number(38), it can hold 38 digits.


Look at Gail's reply and count the number of digits in the answers that she gave you. Do not count the first digit. I do not know if Oracle counts the signs place or not.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87291 Visits: 45272
Ints don't have a max number of digits. They have a minimum and maximum value that they can store. As I gave above.

It's the numeric and decimal datatypes that have a max number of digits.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


RBarryYoung
RBarryYoung
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14740 Visits: 9518
psangeetha (10/14/2008)
Thanks. But application people want to know more about the width rather than the storage size. Like in Oracle we say number(38), it can hold 38 digits.


And just in case you do not already know: the equivalent of Number(38) in SQL Server is NUMERIC(38) or DECIMAL(38).

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
newbieuser
newbieuser
SSC Eights!
SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)

Group: General Forum Members
Points: 841 Visits: 915
Ok Thanks. We are just looking for a datatype we can go with the number of digits.. So the numeric datatype goes with number of digits?? I just tried inserting a record and I think its allowing 18 digits. Please correct me if I am wrong.
If this is correct, we will use number(18) in Oracle.

Thanks.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87291 Visits: 45272
Then you're looking for numeric(18,0)

What did you try inserting and into what datatype?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


newbieuser
newbieuser
SSC Eights!
SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)

Group: General Forum Members
Points: 841 Visits: 915
I tried below


create table test ( a numeric)
insert into test values (999999999999999999)


This worked.

insert into test values (9999999999999999990) didnt work. So I guess the maximum value for numeric datatype is 18
digits.

Is there any other datatype in SQL server that works with the number of digits and not the min max value?

Thanks.
RBarryYoung
RBarryYoung
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14740 Visits: 9518
The thing is, Oracle does not really have binary integer datatypes the way that SQL does. I think that there may be something like PLS_INTEGER which is equivalent to INTEGER in SQL Server, but that is about it.

This makes for real problems when moving data back and forth. Because the SQL Server Integer sizes are between the decimal sizes that Oracle uses, which size you use depends on whether you are moving data from Oracle to SQL Server or from SQL Server to Oracle. Effectively, the receiver of the data always has to round up the number of digits from the sender.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search