Confusing data types in SQL Server_PHP Tutorial

WBOY
Release: 2016-07-13 17:00:31
Original
1219 people have browsed it

I've been doing database design recently, and sometimes I really can't figure out the data types in SQL2000, so I picked up this article.
(1) char, varchar, text and nchar, nvarchar, ntext
The lengths of char and varchar are between 1 and 8000. The difference between them is that char is fixed-length character data, while varchar is a variable-length character data. The so-called fixed length means that the length is fixed. When the length of the input data does not reach the specified length, it will be automatically filled with English spaces after it to make the length reach the corresponding length; while variable-length character data will not be filled with spaces. text stores variable-length non-Unicode data, with a maximum length of 2^31-1 (2,147,483,647) characters.
Compared with the previous ones, the latter three data types only have an extra letter "n" in their names, which indicates that the characters of the Unicode data type are stored. Friends who have written programs should know Unicode very well. Among the characters, English characters only need one byte to store, but there are many Chinese characters, which require two bytes to store. When English and Chinese characters exist at the same time, it is easy to cause confusion. The Unicode character set is to solve the incompatibility problem of character sets. And generated, all its characters are represented by two bytes, that is, English characters are also represented by two bytes. The length of nchar and nvarchar is between 1 and 4000. Compared with char and varchar: nchar and nvarchar can store up to 4000 characters, whether English or Chinese characters; while char and varchar can store up to 8000 English and 4000 Chinese characters. It can be seen that when using nchar and nvarchar data types, you don't have to worry about whether the input characters are English or Chinese characters, which is more convenient, but there is some loss in quantity when storing English.
(2)datetime and smalldatetime
datetime: date and time data from January 1, 1753 to December 31, 9999, accurate to three hundredths of a second.
smalldatetime: Date and time data from January 1, 1900 to June 6, 2079, accurate to the minute.
(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: integer data of 1 or 0.
(4) The two data types decimal and numeric
are equivalent. Both have two parameters: p (precision) and s (number of decimal places). p specifies the maximum number of decimal digits that can be stored to the left and right of the decimal point. 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. The default number of decimal places 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 of real is float(24).


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631233.htmlTechArticleI am doing database design recently, and sometimes I really can’t figure out the data types in SQL2000, so I picked this article . (1)The lengths of char, varchar, text and nchar, nvarchar, ntext char and varchar are all...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template