Follow me. sql: (vi) Serial data type

Source: Internet
Author: User
Tags define character set contains include
Data | Data type the data type of SQL determines how the contents of a field are processed, stored, and displayed in the database. SQL92 defines a standard data type to provide a blueprint for database manufacturers to establish their own data types. In the previous article, we introduced some of the most commonly used data types, which are grouped into four major categories:
Serial
Numerical
Date Time
Interval type

This article will give you an overview of how these data types are used in the database, and then focus on interpreting the serial data types. This information can serve as a useful reference, or as a background for data types in a specific product of a database manufacturer.

Working with Data types
When you create a table in a database, you define the name of each column and the data type of the content to be entered into those columns. To borrow an example from a previous article:

CREATE TABLE Products
(prod_id INT () auto_increment, Prod_color VARCHAR (20),
PROD_DESCR VARCHAR (255), Prod_size DECIMAL (8,2),
UNIQUE (' prod_id '));

In the above query, define row Prod_color VARCHAR (20) Emit instructions to create a column, the name is Prod_color, the data type is VARCHAR, the length is 20.

Your database uses descriptors that are related to each type to distinguish between data types. For example, the information contained in a descriptor for a varchar data type distinguishes it from a serial data type, which contains all the string characters and is variable in length. The definition of a column in a database also contains additional information, such as a specific length corresponding to the data type.

As mentioned earlier, each database manufacturer wants to establish its own data type on the criteria defined by SQL92. This allows each database to set the maximum capacity limits and other properties that it needs when defining data types. Many databases use the same data type names as listed here, although there is a slight difference in each implementation method. The best way to determine the details of how a particular data type uses a method is to consult the database manufacturer's documentation.

As I've already said, I'd like to know more about standard string data types and look down.

String

There are two main serial data types: characters and bits. Serial use the characters defined by Sql_text in the database. The SQL_92 standard also provides the national CHARACTER (country character set) and national CHARACTER varying (country character set variant), both of which can use a definable character set. The latter is treated in the same way as character and character varying types.

CHARACTER | CHAR
How to use: CHARACTER (clength) | CHAR (Clength)

The two keywords character and char are the same.
A prominent feature of the character type is that they can contain <space (blank) > this character.
The CHARACTER type contains a fixed-length string character (from the Sql_text language set), Clength.
<space> character fills when the length of the value is less than clength. This indicates that the length of the character field is fixed.
You can compare character data type fields with other fields of the same type that allow different lengths, or with character varying data types.
Some databases allow comparison with numeric data types.
CHARACTER Varying | CHAR Varying | VARCHAR
How to use: CHARACTER varying (maxlength) | CHAR varying (maxlength) | VARCHAR (maxlength)

CHARACTER Varying,char varying, and varchar are the same as these few keywords.
These types can hold the maximum length of the string, MaxLength.
The database takes the length of the field as the actual length of the value.
You can compare fields of these data types with other fields of the same type that allow different maximum lengths.
BIT

How to use: BIT (blength)

This type contains a bit character with a length (1 and 0), Blength. For example, if we use bit (2), the sample value will be "01".
Some databases insert empty spaces at the beginning of a string, and they fill them to meet fixed-length requirements.
Bit characters are strings, not integers.
You can compare the fields of bit data types with other fields of the same type that allow different lengths, or with bit varying data types.
Some databases allow bits and character or integer types to be compared.
BIT varying

How to use: BIT varying (maxlength)

This type contains the maximum length of the bit character, MaxLength.
The length of the record is set to the actual length of the value.
The database is allowed to compare with its bit varying data field, or with the bit data field.
Do you have some understanding of our SQL series?

Please send your comments, questions or responses to the discussion bar below, or if you have a topic on the SQL Base series, you can send it to our editor's mailbox.

String theory
The database manufacturer creates the data types that you actually want to implement by building the data types of these foundations. For strings, this may include (different) types of the same name, such as char or bit, or extended to include Text,small TEXT, and other data types that contain strings.

This design elasticity creates an obstacle that must be overcome when data is migrated from one database to another. In a database, you might have a type called char that allows maximum capacity greater than the maximum size of the database you want to migrate to. Furthermore, a type that is not explicitly defined in the (SQL92) standard may vary considerably, so that the migration is simplified only by following conventions.

A possible solution to protecting data in the case of a data type migration problem is discussed in the recent article ZDNet China, a blob transplant replacement scheme. The SQL standard does not include metrics for storing binary data, which results in incompatibilities between different database manufacturer products. Software developers must be found to refer to the solution list to remove these barriers.

In the next article in this series, we'll look at SQL92 's digital data types, each with its features, and the requirements for implementing these types of databases.




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.