码迷,mamicode.com
首页 > 数据库 > 详细

7.1The ISO SQL Data Type

时间:2015-04-10 06:35:32      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

In this section we introduce the data types defined in the SQL standard.

We start by defining what constitutes a vailed identifer in SQL.

 

7.1.1  SQL Identifiers

SQL identifiers are identify objects in the database, such as table names, views names, and columns.

The characters that can be used in a user-defined SQL identifier appear in a character set.

The ISO standard provides a default character set, which consists of the uppercase letters A...Z,

the lowercase letters a...z, the digits 0...9, and the underscore (_) character.

The following restrictions are imposed on an identifier:

@ an identifierw can be no longer than 128 characters

(most dialets have a much lower limit than this).

@ an identifier must start with a letter.

@ an identifier cannot contain spaces.

7.1.2 SQL Scalar

Table 7.1 shows the SQL scalar data type defined in the ISO standard.

Sometimes, for manipulation and conversion purpose,

the data types character and bit are collectively referred to as a string data types,

and exact numeric and approximate numeric are referred to as numeric data types, as they share similar properties.

The SQL standard now also defines both character large objects and binary large objects,

although we defer discussion of these data type until Section 29.4.

 

Boolean data

 

Boolean data consists of the distinct truth value TRUE and FALSE.

Unless prohibited by a NOT NULL constraint, boolean data also supports the UNKNOWN truth values as NULL value. 

All boolean data type values and SQL truth values are mutually comparable and assignable.

 

The value TRUE is greater than the value FALSE,

and  any comparison involving the NULL value or an UNKNOWN truth value returns an UNKNOWN result.

Character data

Character data consists of a sequence of characters from an implementation-defined character set,

that is, it is defined by the vender of the particular SQL dialet.

Thus, the exact characters that can appear as data values in a character type column will vary.

ASCII and EBCDIC are two sets in common use today.

The format for specifying a character data type is :

CHARACTER [VARYING][length]

  CHARACTER can be abbreviated to CHAR and

  CHARACTER VARYING to VACHAR.

When a character string column is defined,

a length can be specified to indicate the maximum number of characters that the column can hold (default length is 1) .

A character string may be defined as having a fixed or varying length.

If the string is defined to be a fixed length and we enter a string with fewer characters than this length,

the strings is padded with blanks on the right to make up the required size.

 

If the string is defined to be of a varying length and we enter a string with fewer characters than this lenth, only those characters entered are stored, thereby using less space.

For example, the branch number column column branchNo of the Branch number column branchNo of the Branch table, which has a fixed length of four characters, is declared as:

BranchNo CHAR(4)

The column address of the PrivateOwner table, which has a variable number of characters up to a maximum of 30, is declared as:

address VARCHAR = (30)

 

7.1The ISO SQL Data Type

标签:

原文地址:http://www.cnblogs.com/666638zhangqiang/p/4410519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!