What data types does SQL support and how to choose when using them?

In the previous article, we discussed how to design the database structure, and specifically introduced entity relationship diagrams and standardization techniques.

When designing an ERD, you first need to define entities and their attributes, that is, define the structure of the table. When defining the table structure, you first need to confirm which fields are included in the table and the data types of the fields. Today we will learn how to choose the appropriate data type for the fields in the table.

Common data types

The data type of the field defines the data values ​​that the field can store and the operations that are allowed to be performed. The following figure lists the common data types in SQL, including string type, number type, date and time type, and binary type.

data type

We have introduced the functions and type conversion functions related to these data types in Chapter 8, Chapter 9, and Chapter 10.

String type

The string type is used to store characters and string data, and it mainly includes three specific types: fixed-length strings, variable-length strings, and string large objects. Various databases support the string type as follows:

</
type of data Oracle MySQL SQL Server PostgreSQL
Fixed-length string CHAR(n) CHAR(n) CHAR(n) CHAR(n)
Variable length string VARCHAR2(n) VARCHAR(n) VARCHAR(n) VARCHAR(n)

Guess you like

Origin blog.csdn.net/horses/article/details/108729090
Recommended