SQL Server numeric data types

Reprinted from the product is slightly Library  http://www.pinlue.com/article/2019/03/2912/078473755807.html

Numeric (10,2) refers to a numeric field, a length of 10 decimal to a brief description of what the two five data types in SQL: character, type text, numeric, character, and dates logic VARCHAR VS CHAR the difference between VARCHAR and CHAR type data type is subtle, but very important.

They are used to store a character string length of less than 255. If the input data type field you Bill Gates VARCHAR to a length of forty characters. When you later removed from the data in this field, you remove data having a length of ten characters - Bill Gates of the length of the string. Now, if you enter a string length of forty characters of type CHAR field, then when you extracted data, the extracted data will be forty characters in length.

The end of the string is appended extra space. When you build your own site, you will find that the use of VARCHAR type field than CHAR type field more convenient. When using the VARCHAR type field, you do not need to cut your data in the extra space to worry about. Another outstanding benefit of VARCHAR type field is that it can take up less memory and disk space than CHAR type field. When you have a large database, this saving will become memory and disk space is very important to use the text-based TEXT text-based data, you can store the string more than two billion characters. When you need to store large character strings, you should use text-based data.

Note that there is no text-based data length, and the upper section of the spoken character data is length. A text data type field usually either empty or very large. When you collect the data from the HTML form of multi-line text edit box (TEXTAREA), you should put the information collected is stored in a text type field. However, whenever you can avoid the use of text-type field, you should not apply it. Both large type text field Wait a minute, abuse text type field causes the server to slow down. Text type field also eat a lot of disk space. Once you enter any data (even null) to type a text field, there will be 2K space is automatically allocated to the data. Unless delete the record, otherwise you can not recover this part of the storage space.

Numeric SQL supports many different types of numeric data. You can store integer INT, fractional NUMERIC, and the amount of money MONEY. INT VS SMALLINT VS TINYINT their difference is the character length: INT table number range data type is an integer type SMALLINT -2,147,483,647 to 2,147,483,647 data may be stored from -32768 to 32768 TINYINT integer type field can only store an integer from 0 to 255, generally can not be used to store a negative number, in order to save space, should use the smallest possible integer data.

TINYINT only a one byte data type; a type INT data occupies four bytes. This may seem very different, but in the larger table, the number of bytes growth is very fast. On the other hand, once you have created a field, you want to modify it is very difficult. Therefore, for safety reasons, you should predict the following, a field that needs to store the maximum possible value is how much, and then select the appropriate data type.

MUNERIC order to have more control over the data stored in the field, you can use the data type NUMERIC simultaneously represent integer and fractional part of a number. NUMERIC data type so that you can represent very large numbers - is much greater than the INT data type. NUMERIC type field may store a number from the range of -1038 to 1038. NUMERIC data type also enables you to have represented the number of fractional part.

For example, you can store 3.14 in decimal NUMERIC type field. When defining a NUMERIC type field, you need to specify the size and the size of the integer portion of the fractional part. Such as: MUNERIC (23,0) the integer part of a data type NUMERIC only 28 maximum number of bits fractional bits must be less than or equal to the integer part, the fractional part may be zero.

MONEY VS SMALLMONEY you can use INT type or NUMERIC data type to store the amount of money. However, there are two other special data types for this purpose. If you want to earn a lot of money on your network, you can use the data type MONEY. If your ambition is not, you can use SMALLMONEY type data. MONEY type of data can be stored for money from -922,337,203,685,477.5808 to 922, 337,203,685,477.5807 of. If you need to store larger amounts than this, you can use the NUMERIC data type.

SMALLMONEY data type can only store a number from -214,748.3648 to 214,748.3647 money. Similarly, if you can, you should use SMALLMONEY type instead of MONEY data type, to save space. Logical BIT If you are using check boxes (CHECKBOX) to collect information from the web, you can put this information is stored in the BIT type field. BIT type field can only take two values: 0 or 1.

Beware, after you created a table, you can not add BIT type field to the table. If you intend to include BIT type field in a table, you must complete when creating a table. Date type DATETIME DATETIME VS SMALLDATETIME a type field may store a first date range from milliseconds to December 31, 9999 January 1, 1753 the last millisecond. If you do not need to cover such a large range of dates and times, you can use SMALLDATETIME type data.

It also uses the DATETIME data type, but the date and time range it represents less than DATETIME type of data, but not as good as the data type DATETIME precision. SMALLDATETIME type of a field can store dates from January 1, 1900 to June 6, 2079, which is only accurate to the second. DATETIME type field does not contain the actual data before you enter the date and time, realize this is important.

 

Published 60 original articles · won praise 58 · Views 140,000 +

Guess you like

Origin blog.csdn.net/yihuliunian/article/details/105389418