Integer Data Type in SQLserver

Source: Internet
Author: User
In SQLServer, there are four types of integer data: bigint, int, smallint, and tinyint. They are distinguished by the number of digits they occupy. Bigint: 8 bytes, 64-bit. Integer Data int from-2 ^ 63 (-9223372036854775808) to 2 ^ 63-1 (9223372036854775807): 4 bytes, 32 bits. From-2 ^ 31 (-2,

In SQL Server, there are four types of integer data: bigint, int, smallint, and tinyint. They are distinguished by the number of digits they occupy. Bigint: 8 bytes, 64-bit. Integer Data int from-2 ^ 63 (-9223372036854775808) to 2 ^ 63-1 (9223372036854775807): 4 bytes, 32 bits. From-2 ^ 31 (-2,

Integer type in SQL ServerDataTypeThere are four types of bigint, int, smallint, and tinyint. They are distinguished by their digits.


Bigint: 8 bytes, 64-bit. Integer from-2 ^ 63 (-9223372036854775808) to 2 ^ 63-1 (9223372036854775807)Data

Int: 4 bytes, 32 bits. Integer from-2 ^ 31 (-2,147,483,648) to 2 ^ 31-1 (2,147,483,647)Data

Smallint: occupies 2 bytes, 16 bits. Integer from-2 ^ 15 (-32,768) to 2 ^ 15-1 (32,767)Data

Tinyint: takes 1 byte and 8 bits. Integer from 0 to 255Data


Note

Bigint is supported where integer values are supported.DataType. However, bigint is used in some special cases when the integer value exceeds int.DataTypeBigint can be used when the range is supported. In SQL Server, intDataTypeIs a major integer.DataType.

InDataTypeIn the priority table, bigint is located between smallmoney and int.

Only when the parameter expression is bigintDataTypeThe function returns bigint. SQL Server does not automatically add other integersDataType(Tinyint, smallint, and int) to bigint.

Summary

So select the most appropriateDataTypeIt is very important. For example, if you have 10 18 digits, they are all digital ID card numbers, and 10 15 digits are all digital ID card numbers. Let you find the 20 records at the fastest query speed. When designing this field, you should pay attention to the following points:

1. The fastest query speed is nothing more than int.TypeOfDataTo store the 20 ID card numbers. HoweverDataIt seems that only bigint meets the condition.

2. Why not use varchar or char. Directly save it as a string. The query speed of int must be faster than that of varchar and char.TypeOfDataIs the first choice, but there are several int types in sqlserver. Select the most appropriate one.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.