Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the field types in SQL SERVER

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

What are the field types in SQL SERVER? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Instructions provided by SQL SERVER.

Integer numbers for bit:0 or 1

Int: integer numbers from-2 ^ 31 (- 2147483648) to 2 ^ 31 (2147483647)

Smallint: integer numbers from-2 ^ 15 (- 32768) to 2 ^ 15 (32767)

Tinyint: integer numbers from 0 to 255

Decimal: the number of fixed precision and significant digits from-10 ^ 38 to 10 ^ 38-1

Synonym for numeric:decimal

Money: currency data from-2 ^ 63 (- 922337203685477.5808) to 2 ^ 63-1 (922337203685477.5807), the smallest monetary unit is 10/1000

Smallmoney: currency data from-214748.3648 to 214748.3647, minimum currency unit 10/1000

Float: a variable precision number from-1.79E+308 to 1.79E+308

Real: a variable precision number from-3.04E+38 to 3.04E+38

Datetime: date and time data from January 1, 1753 to December 31, 9999, with a minimum time unit of 3% seconds or 3.33ms

Smalldatetime: date and time data from January 1, 1900 to June 6, 2079, minimum time in minutes

Timestamp: timestamp, a unique number for the width of a database

Uniqueidentifier: globally unique identifier GUID

Char: fixed-length non-Unicode character data with a maximum length of 8000

Varchar: variable length non-Unicode character data with a maximum length of 8000

Text: variable length non-Unicode character data with a maximum length of 2 ^ 31-1 (2G)

Nchar: character data of fixed-length Unicode, with a maximum length of 8000

Nvarchar: character data of variable length Unicode, with a maximum length of 8000

Ntext: character data of variable length Unicode with a maximum length of 2 ^ 31-1 (2G)

Binary: fixed-length binary data with a maximum length of 8000

Varbinary: variable length binary data with a maximum length of 8000

Image: variable length binary data with a maximum length of 2 ^ 31-1 (2G)

Brief introduction

MS's SQL Server is mainly made up of five commonly used fields, character, text, numeric, logical, and date! Many friends are at a loss because of the mismatch of field types after ACCESS is converted to SQL in some BBS. Let's introduce some of the characteristics of each of these five data types.

Text

[1] character type data Varchar, chartype

When we need to store relatively short string information in the program, we will use character data, and there are two types of character data in SQL! VARCHAR and Char, the difference between the two types of data is very subtle, but very important!

For example, when you enter a 4-character string TOL8 into a 40-character VARCHAR field, the length of the data is 4 characters, and if you replace VARCHAR with Char, you will take out data of 40 characters, and extra spaces will be added to the string. For example, TOL8 has only 4 characters, so the data taken out from CHAR is TOL8 plus 36 spaces! In the specific programming, I personally recommend the VARCHAR type, because from some references I found that the VARCHAR type takes up less hard disk memory than CHAR!

VARCHAR stores a maximum of 255characters, beyond which we will use the textual data we will talk about below.

[2] text data Text

You can store more than 2 billion strings in text data. How about that? is this big enough? But it is not always and use text-based data, because it takes up a lot of space, but also consumes a lot of servers, the consequences of misuse everywhere are unimaginable! Because even if you enter a null value like a text field, it will take up 2K of space! At this time, there is no other way to recover the space except to delete the data!

[3] data Int,Tinying,Numeric

SQL supports many different data types, allowing you to store integers, decimals, and money!

INT (integer data) represents an integer from-2147483647 to 2147483647

If your number is not that long, to save memory space, you can use SMALLINT which ranges from-32768 to 32768 integers! The two are used in exactly the same way!

If you want to save more space, you can choose to use TINYINT, which can only store integers from 0 to 255. note that TINYINT cannot store negative numbers, a TINYINT takes one byte, and an int data takes 4 bytes!

[4] data Bit

The web page check box collects information and stores it in the database, which is the most common use of bit! He only has two values: 0 or 1.

[5] data Datetime,Samlldatetime

The storage range of DATETIME is from the first millisecond of January 1, 1753 to the last millisecond of December 31, 9999. If you do not need such a large date range, you can choose to use SMALLDATETIME. Its storage range is from January 1, 1900 to June 6, 2079, but only to seconds!

[6] Special data Cursor

The answers to the questions about the field types in SQL SERVER are shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report