What are the common data types in databases?
#What are the common data types in databases?
1. Integer data type: The integer data type is one of the most commonly used data types.
1. INT (INTEGER)
INT (or INTEGER) data type stores values from -2 to the 31st power (-2, 147, 483, 648) to all positive and negative integers between 2 to the 31st power -1 (2, 147, 483, 647). Each INT type data is stored in 4 bytes, of which 1 bit represents the sign of the integer value, and the other 31 bits represent the length and size of the integer value.
2, SMALLINT
SMALLINT data type stores from -2 to the 15th power (-32, 768) to 2 to the 15th power -1 (32, 767 ) between all positive and negative integers. Each SMALLINT type data occupies 2 bytes of storage space, of which 1 bit represents the sign of the integer value, and the other 15 bits represent the length and size of the integer value.
2. Floating point data type: Floating point data type is used to store decimal decimals. Floating-point numerical data is stored in SQL Server using round up (or called rounding only) method.
1. REAL data type
REAL data type can be accurate to the 7th decimal place, and its range is from -3.40E -38 to 3.40E 38 . Each REAL type data occupies 4 bytes of storage space.
2. FLOAT
The FLOAT data type can be accurate to the 15th decimal place, and its range is from -1.79E -308 to 1.79E 308. Each FLOAT type data occupies 8 bytes of storage space. The FLOAT data type can be written in the form of FLOAT[n]. n specifies the precision of FLOAT data. n is an integer value between 1 and 15.
When n ranges from 1 to 7, a REAL type data is actually defined, and the system uses 4 bytes to store it; when n ranges from 8 to 15, the system considers it to be a FLOAT type, and uses 8 bytes to store it.
3. Binary data type
1. BINARY
BINARY data type is used to store binary data. Its definition form is BINARY (n), n represents the length of the data, and its value ranges from 1 to 8000. The size of BINARY type data must be specified when using it, which should be at least 1 byte. BINARY type data occupies n 4 bytes of storage space.
When entering data, the character "0X" must be added in front of the data as a binary identifier. For example, if you want to enter "abc", you should enter "0xabc". If the input data is too long, the excess part will be truncated. If the input data has an odd number of digits, a 0 will be added after the starting symbol "0X". For example, the above "0xabc" will be automatically changed to "0x0abc" by the system.
2. VARBINARY
The definition form of VARBINARY data type is VARBINARY(n). It is similar to the BINARY type. The value of n is also from 1 to 8000. If the input data is too long, the excess part will be truncated.
The difference is that the VARBINARY data type has the characteristic of variable length, because the storage length of the VARBINARY data type is the actual value length of 4 bytes. When the BINARY data type allows NULL values, it will be treated as a VARBINARY data type.
4. Logical data type
1. BIT: The BIT data type occupies 1 byte of storage space, and its value is 0 or 1 . If you enter a value other than 0 or 1, it will be treated as 1. The BIT type cannot be defined as a NULL value (the so-called NULL value refers to a null value or a meaningless value).
5. Character data type: Character data type is the most commonly used data type. It can be used to store various letters, numeric symbols, and special symbols. Under normal circumstances, when using character type data, single quotes ' or double quotes must be added before and after it.
1, CHAR
CHAR data type The definition form is CHAR[(n)]. Each character and symbol stored in the CHAR type occupies one byte of storage space. n represents the storage space occupied by all characters, and the value of n is 1 to 8000, that is Holds 8000 ANSI characters.
If n value is not specified, the system default value is 1. If the number of characters of the input data is less than n, the system will automatically add spaces after it to fill the set space .If the input data is too long, the excess part will be cut off.
Extended information:
SQL includes all operations on the database, mainly composed of 4 It consists of three parts:
1. Data definition: This part is also called "SQL DDL", which defines the logical structure of the database, including defining the database, basic tables, views and indexes.
2. Data manipulation: This part is also called "SQL DML", which includes two major types of operations: data query and data update. Data update includes three operations: insertion, deletion and update.
3. Data Control: Control of user access to data includes authorization of basic tables and views, description of integrity rules, transaction control statements, etc.
4. Regulations on the use of embedded SQL language: stipulates that SQL statements must be used in the host language Rules used in the program.
Recommended tutorial: "sql video tutorial"
The above is the detailed content of What are the common data types in databases?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.
