SQL SERVER data types

  Lane is a data class attribute data, data indicating the type of information represented. Any kind of computer language defines its own data types. Of course, different programming languages have different characteristics, data types defined in the types and names are more or less different. SQLServer provides 25 data types:
  · Binary [(n-)]
  · Varbinary [(n-)]
  · Char [(n-)]
  · Varchar [(n-)]
  · Nchar [(n-)]
  · Nvarchar [(n-)]
  · Datetime
  · Smalldatetime
  · a Decimal [(P [, S])]
  · Numeric [(P [, S])]
  · the Float [(n-)]
  · Real
  · Int
  · Smallint
  · Tinyint
  · Money
  · smallmoney
  · Bit
  · the Cursor
  · sysname
  · Timestamp
  · Uniqueidentifier
  · Text
  · Image
  · Ntext

(1) the type of binary data

  Binary data including Binary, Varbinary and Image
  Binary data types can be either a fixed length (Binary), may be of variable length.
  Binary [(n)] is a fixed n-bit binary data. Wherein, n for the range from 1 to 8000. Its size is stored scenting n + 4 bytes.
  Varbinary [(n)] n-bit binary data of variable length. Wherein, n for the range from 1 to 8000. Its size is stored scenting n + 4 bytes, not n bytes.
  Image data stored in the data type is stored in the bit string is not interpreted by SQL Server, and must be interpreted by the application. For example, an application can use BMP, TIEF, GIF and JPEG Image data stored in the data type.

(2) character data type

  Character data types include Char, Varchar and Text
  character data is data of any letters, numbers and symbols in any combination.
  Varchar character data is variable length, its length does not exceed 8KB. Char length is a fixed character data having a length up to 8KB. 8KB of data than ASCII Text data type can be used to store. For example, because Html documents are all ASCII characters, and in general longer than 8KB, so these documents can be stored in the Text data type in SQL Server.

(3) Unicode data type

  Unicode data types include Nchar, Nvarchar and Ntext
  In Microsoft SQL Server, the traditional non-Unicode character types allow data defined by a particular character set. In SQL Server installation process, allowing to select a character set. Using Unicode data types, any character row may be stored by the Unicode standard definition. In the Unicode standard includes characters of all the various character sets defined. Using Unicode data types, the cellar is overcome by the use of non-Unicode data types twice occupied by the size of the cellar.
  In SQL Server, Unicode data Nchar, Nvarchar and Ntext data type stores. With this type of characters stored in the character column can store a plurality of character set. When the change in length of the column should be used Nvarchar character type, case can store up to 4000 characters. When the fixed length of the column, should be used Nchar character type, the same, then you can store up to 4000 characters. When using Ntext data type, the column can store more than 4000 characters.

(4) the date and time data types

  Date and time data types include Datetime Smalldatetime and two types of
  date and time data types by the effective date, and time. For example, the effective date and time data includes "4/01/98 12: 15: 00: 00: 00 PM" and "1: 28: 29: 15 : 01AM 8/17/98". Before a date data type is the front, a time after the first data type is a sudden, after date. In Microsoft SQL Server, the date and time data types including Datetime and Smalldatetime two types, the stored date range from January 1, 1753 start, 9999 ended December 31 (each value requirements 8 memory byte). When using Smalldatetime data type, the date range is stored beginning January 1, 1900, to December 31, 2079 End (each value claim 4 bytes of storage).
  Format of the date can be set. Set the date format command is as follows:
  the Set the format DateFormat {| @format _var |
  wherein, format | @format_var the order date. Effective parameters include MDY, DMY, YMD, YDM, MYD and DYM. By default, the date format is MDY.
  For example, after execution Set DateFormat YMD, the date format for the date the form; when the execution Set DateFormat DMY, the date format for the sun and the moon for years in the form of

(5) the type of digital data

  Digital data contain only numbers. Numeric data types comprise positive and negative numbers, decimals (floating point) and an integer of
  an integer of a positive and negative integers composition, e.g. 39,25,0-2 and 33967. In Micrsoft SQL Server, the integer data type is stored   Int, Smallint and Tinyint . Int range larger than the data type for storing data stores data of data Smallint range while Smallint stores data according to a range of greater than Tinyint data type for storing data. Int dogs using past data stored in the data range is from -2147483648 to 2147483647 (each value requires four bytes of storage). When using Smallint data type, the data stored in the range from -32768 to 32767 (each value requires 2 bytes of storage). When using Tinyint data type, the data is stored in the range from 0 to 255 (each of value 1 byte of storage space required).
  Lou accurate small data type in SQL Server is Decimal and Numeric. Such data storage space occupied by the number of bits is determined according to the number of bits of the data.
  In SQL Server, data approximate decimal data type is Float and Real. For example, one-third of the score recorded as. 3333333, when accurately represents approximate data types. Thus, the system is retrieved from the data may not be exactly the same as the data stored in that column.

(6) data representing monetary positive or negative amount of money.

  In Microsoft SQL Server, the data type money data is Money and Smallmoney

  Money data type requires 8 bytes of storage, Smallmoney data type requires four bytes of storage.

(7) special data types

  Special data types not previously mentioned data type. Special data types are three kinds, i.e.   Timestamp, Bit and Uniqueidentifier .
  Timestamp is used to indicate the sequence of SQL Server activity, expressed in binary format projection. Timestamp data and data insertion or not related to the date and time.
  Bit 0 or 1 by the composition. When showing true or false, ON or OFF, using Bit data type. For example, asking whether the client request can access every type of data stored in this column.
  Uniqueidentifier a 16 byte hexadecimal number, it represents a globally unique. When the rows of the table the only requirement, GUID is very useful. For example, such data types can be distinguished using different customers in customer identification number column.

2. The user-defined data types

  User-defined data type based on the type of data provided in Microsoft SQL Server. When several tables must be stored in the same data type, and to ensure that these columns have the same data type, and the length of the air, can be user-defined data types. For example, it called postal_code defined data type, which is based on data type Char.
  When creating a user defined data type, must provide three numbers: Name of the data type, the type of system data and of data types is based may be empty.

(1) create a user-defined data types

  Create a user-defined data types can use Transact-SQL statements. Sp_addtype system stored procedures can create user-defined data types. Its syntax is as follows:
  the sp_addtype type} {, [, system_data_bype] [, 'null_type']
  wherein, type is the name of the user-defined data types. system_data_type type system is provided, e.g. Decimal, Int, Char like. null_type indicates that the data type is how to handle null values, must be enclosed in single quotes, for example, 'NULL', 'NOT NULL' or 'NONULL'.
  Examples:
  the Use, CUST
  Exec the sp_addtype SSN, 'Varchar (11)', "Not Null '
  to create a user-defined data types SSN, type system which is based on the variable length of 11 characters, do not allow air.
  Examples:
  the Use, CUST
  Exec sp_addtype birthday, datetime, 'null '
  to create a user-defined data types birthday, type system which is based on the dateTime, allows null.
  examples:
  the Use Master
  exec the sp_addtype Telephone, 'VARCHAR (24),' Not null '
  Eexc the sp_addtype fax, 'varchar (24)' , '

(2) delete the user-defined data types

  When the user-defined data types do not need to be deleted. Delete the user-defined data type of command is sp_droptype { 'type'}.
  Examples:
  the Use Master
  Exec sp_droptype 'SSN'
  Note: When the columns in the table is also user-defined data types, or have a default binding or the rule further thereon, the user-defined data types that can not be deleted.

SQL SERVER fields Type Description

  The following is the SQL SERVER7.0 above the field type description. SQL SERVER6.5 field type description Refer to the instructions provided by SQL SERVER.

Field Type description
 bit  Integer number 0 or 1,
 int  From -2 ^ 31 (2,147,483,648) to 2 ^ 31 (2,147,483,647) integer numbers
 smallint  From -2 ^ 15 (-32,768) through 2 ^ 15 (32,767) integer numbers
 tinyint  Integer numbers from 0 to 255
   
 decimal  From a given accuracy -10 ^ 38 to 10 ^ 38-1 and the effective number of digits
 numeric  decimal synonyms
   
 money  Money data from -2 ^ 63 (-922,337,203,685,477.5808) to 2 ^ 63-1 (922,337,203,685,477.5807), the minimum unit of currency thousandths
 smallmoney  -214,748.3648 currency data to 214,748.3647 from the smallest unit of the currency thousandths
   
 float  -1.79E + 308 from the digital to the variable precision 1.79E + 308
 real  Variable digital precision from -3.04E + 38 to 3.04E + 38
   
 datetime  Date and time data 1 January 1753 to 12 May 9999 31 years from the smallest unit of time is three seconds or 3.33 percent milliseconds
 smalldatetime  Date and time data January 1, 1900 to June 6, 2079 from the minimum time in minutes
   
 timestamp  The only digital time-stamping, a width of the database
 uniqueidentifier  GUID Globally Unique Identifier
   
 char  Fixed-length non-Unicode character data, the maximum length of 8000
 varchar  Variable-length non-Unicode character data, the maximum length of 8000
 text  Variable-length non-Unicode character data, the maximum length of 2 ^ 31-1 (2G)
   
 nchar  Unicode character data of fixed length, the maximum length of 8000
 nvarchar  Unicode character data of variable length, the maximum length of 8000
 ntext  Unicode character data of variable length, the maximum length of 2 ^ 31-1 (2G)
   
 binary  Fixed-length binary data, the maximum length of 8000
 varbinary  Variable-length binary data, the maximum length of 8000
 image  Variable-length binary data, the maximum length of 2 ^ 31-1 (2G)

 

Reproduced in: https: //www.cnblogs.com/Spring/archive/2005/04/25/144773.html

Guess you like

Origin blog.csdn.net/weixin_33728708/article/details/93932384