Current location - Health Preservation Learning Network - Fitness coach - How does SQL create a field of date type?
How does SQL create a field of date type?
The data type of 1.SQL Server is an attribute of data, indicating the information type represented by the data. Any computer language defines its own data type. Of course, different programming languages have different characteristics, and the types and names of defined data types are more or less different. SQLServer provides 25 data types: binary [(n)] varbinary [(n)] char [(n)] varchar [(n)] nchar [(n)] nvarchar [(n)] datetime smalldatetime decimal [(p) s]) numeric [(p [ S])] float [(n)] real int small tinyint money small money bit cursor sysname timestamp unique identifier text image ntext (1) binary data type binary data, Include Binary, Varbinary and Image Binary, where Binary[(n)] is n-bit fixed binary data. Where the value range of n is from 1 to 8000. Its storage size is n+4 bytes. Varbinary[(n)] is n-bit variable-length binary data. Where the value range of n is from 1 to 8000. Its storage size is n+4 bytes, not n bytes. The data stored in the Image data type is stored as a bit string, which is not interpreted by SQL Server and must be interpreted by the application. For example, applications can use BMP, TIEF, GIF and JPEG formats to store data of image data types. (2) Character data types Character data types include Char, Varchar and Text. Character data is data composed of any combination of letters, symbols and numbers. Varchar is variable-length character data, with a length of less than 8KB. Char is fixed-length character data with a maximum length of 8KB. ASCII data exceeding 8KB can be stored using text data types. For example, because Html documents are all ASCII characters, and in general, they are all longer than 8KB, so these documents can be stored as text data types in SQL Server. (3)Unicode data types Unicode data types include Nchar, Nvarchar and Ntext. In Microsoft SQL Server, traditional non-unicode data types allow the use of characters defined by a specific character set. During the installation of SQL Server, you can choose a character set. With the Unicode data type, any character defined by the Unicode standard can be stored in a column. In the Unicode standard, all characters defined in various character sets are included. Using Unicode data types can overcome twice the size of using non-unicode data types. In SQL Server, Unicode data is stored in Nchar, Nvarchar and Ntext data types. Columns stored with this character type can store characters in multiple character sets. When the length of a column changes, you should use the Nvarchar character type, which can store up to 4000 characters. When the length of the column is fixed, the Nchar character type should be used. Similarly, you can store up to 4000 characters. When using the Ntext data type, this column can store more than 4000 characters. (4) Date and time data types Date and time data types include Datetime and Smalldatetime. The date and time data type consists of valid dates and times. For example, valid date and time data include "4/01/9812:15: 00: 00 pm" and "1:28: 29:15: 0/kloc". The former data type is the date before and the time after, and the latter data type is the time before and the date after. In Microsoft SQL Server, when the date and time data types include Datetime and Smalldatetime, the stored date ranges from 1753 1 to 9999 12 3 1 (each value needs 8 storage bytes). When using the Smalldatetime data type, the stored date range is 1900 65438+ 10/0, ending at February 3, 2079 1 (each value needs 4 storage bytes). You can set the date format. The command to set the date format is as follows: Set the date format {format | @format_var | where format | @format_var is the order of the dates. Valid parameters include MDY, DMY, YMD, YDM, MYD and DYM. By default, the date format is MDY. For example, when setting date format YMD is executed, the date format is year, month and day format; After executing Set DateFormat DMY, the date format is in the form of day, month and year. (5) Digital data type Digital data only contains numbers. Numeric data types include positive and negative numbers, decimals (floating point numbers) and integers. Integers consist of positive and negative integers, such as 39, 25, 0-2 and 33967. In Micrsoft SQL Server, the data types of integer storage are int, Smallint and Tinyint. The data range stored by Int data type is larger than that stored by Smallint data type, while the data range stored by Smallint data type is larger than that stored by Tinyint data type. The range of using Int data type to store data is from -2 147 483 648 to 2 147 483 647 (each value requires 4 bytes of storage space). When using the Smallint data type, the range of stored data is from -32 768 to 32 767 (each value requires 2 bytes of storage space). When using the Tinyint data type, the range of stored data is from 0 to 255 (each value requires 1 byte storage space). The data types of precise decimal data in SQL Server are decimal and numerical. The storage space occupied by this kind of data is determined according to the number of bits after the number of data bits. In SQL Server, the data types of approximate decimal data are Float and Real. For example, one-third of this score is recorded as. 3333333, which can be accurately expressed when using approximate data types. Therefore, the data retrieved from the system may not be exactly the same as the data stored in this column. (6) Monetary data indicates positive or negative monetary quantity. In Microsoft SQL Server, the data types of currency data are Money and Smallmoney. The money data type needs 8 storage bytes, and the small money data type needs 4 storage bytes. (7) Special data types Special data types include data types not mentioned before. There are three special data types, namely timestamp, bit and unique identifier. Time stamp is used to indicate the sequence of SQL Server activities and is expressed in binary projection format. Timestamp data has nothing to do with inserted data or date and time. Bit consists of 1 or 0. When representing true or false, on or off, the bit data type is used. For example, a client request asking whether every access can be stored in a column of this data type. Uniqueidentifier is composed of hexadecimal digits of 16 bytes, representing a globally unique. GUID is very useful when the record rows of a table need to be unique. For example, using this data type in the customer identification number column can distinguish different customers.