Easy-to-confuse data types in SQL Server _php tutorial

Source: Internet
Author: User
Recently in the database design, sometimes really confusing SQL2000 data types, so picked this article.
(1) Char, varchar, text and nchar, nvarchar, ntext
Char and varchar are between 1 and 8000 in length, the difference being that char is a fixed-length character data, and varchar is a variable-length character data. The so-called length is fixed, when the input data length does not reach the specified length will be automatically filled with English space after it, so that the length of the corresponding length, and the variable length character data will not be filled with spaces. Text stores non-Unicode data of variable length, with a maximum length of 2^31-1 (2,147,483,647) characters.
The next three data types, compared to the previous one, are just a few letters "n" from the name, which represents the characters that are stored in the Unicode data type. A friend who has written a program should know a lot about Unicode. Character, the English characters only need one byte storage is sufficient, but the Chinese character is numerous, requires two bytes of storage, English and Chinese characters are prone to confusion, the Unicode character set is to solve the problem of incompatible character sets, all of its characters are represented by two bytes, That is, the English character is also represented in two bytes. The length of the nchar and nvarchar is between 1 and 4000. Compared to char and varchar: nchar, nvarchar stores up to 4,000 characters, whether in English or Chinese characters, while char and varchar can store up to 8,000 English and 4,000 Chinese characters. It can be seen that the use of nchar, nvarchar data types without worrying about the input characters are English or Chinese characters, more convenient, but in the storage of English number of some losses.
(2) datetime and smalldatetime
DateTime: Date and Time data from January 1, 1753 to December 31, 9999, accurate to 3% seconds.
smalldatetime: Date and time data from January 1, 1900 to June 6, 2079, accurate to minutes.
(3) bitint, int, smallint, tinyint, and bit
bigint: Integer data from -2^63 (-9223372036854775808) to 2^63-1 (9223372036854775807).
int: integer data from -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647).
smallint: Integer data from -2^15 (-32,768) to 2^15-1 (32,767).
Tinyint: Integer data from 0 to 255.
Bit:1 or 0 of integer data.
(4) Decimal and numeric
Both of these data types are equivalent. have two parameters: P (Precision) and S (decimal digits). p Specifies the maximum number of decimal digits that can be stored to the left and right of the decimal point, and P must be a value from 1 to 38. s specifies the maximum number of decimal digits that can be stored to the right of the decimal point, s must be a value from 0 to P, and the default scale is 0.
(5) Float and real
float: Floating-point numeric data from -1.79^308 to 1.79^308.
Real: Floating-point numeric data from -3.40^38 to 3.40^38. In SQL Server, the synonym for Real is float (24).


http://www.bkjia.com/PHPjc/631233.html www.bkjia.com true http://www.bkjia.com/PHPjc/631233.html techarticle recently in the database design, sometimes really confusing SQL2000 data types, so picked this article. (1) The lengths of char, varchar, text and nchar, nvarchar, ntext char, and varchar ...

  • 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.