Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the field types in MySQL

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces what field types there are in MySQL, the content is very detailed, interested friends can refer to it, I hope it can be helpful to you.

What are the MySQL field types?

Type description

INT is a numeric type whose range of values is as follows: signed-214748364804294967295 unsigned-2147483647, so it is not possible to store a mobile phone number.

DECIMAL A numeric type that supports floating-point or decimal numbers

DOUBLE is a numerical type that supports double-precision floating-point numbers

Date field in DATEYYYYMMDD format

Time field in TIMEHH:MM:SS format

Date / time type in DATETIMEYYMMDDHH:MM:SS format pay attention to the space between "year, month, day" and "hour, minute and second"

YEAR is in YYYY or YY format, and the range is between 1901 and 2155. Don't ask me what to do after 2155. I don't think I will live to that year.

TIMESTAMP timestamp in YYYYMMDDHHMMSS format

CHAR string type with a maximum length of 255characters and a fixed length

VARCHAR string type with a maximum length of 255characters but a variable length

The type of string with a maximum length of 65535 characters in TEXT

Binary types of BLOB variable data

ENUM can accept data types of values from a list that defines numeric values

SET can accept data types of 0 or more values from a collection that defines values

How to realize the self-growth of MySQL field

CreatetabletableName (idunsignedintprimarykeyauto_incrementnotnull,titlevarchar 32), contenttext)

Auto_increment is the attribute of self-growth.

How mysql specifies id and then grows itself

Auto_increment=100

Make MySQL self-growing field numbers from non-continuous to continuous

ALTERTABLEtablenameDROPid;ALTERTABLEtablenameADDidINTNOTNULLPRIMARYKEYAUTO_INCREMENTFIRST

If mysql's self-growing ID (int) is not enough, use bigInt instead.

In Mysql:

INT [(M)] [UNSIGNED] [ZEROFILL]

A normal size integer. The signed range is-2147483648 to 2147483647, and the unsigned range is 0 to 4294967295.

BIGINT [(M)] [UNSIGNED] [ZEROFILL]

A large integer. The signed range is-9223372036854775808 to 9223372036854775807, and the unsigned range is 0 to

18446744073709551615

Get the maximum ID,selectmax (id) fromtableName from MySQL

Realize the self-increment of ID

Publicintmaxid () throwsSQLException {stmt=conn.createStatement (); rs=stmt.executeQuery ("selectmax (id) fromtableName"); intmaxid=1;while (rs.next ()) {maxid=rs.getInt (1) + 1;} returnmaxid;}

About which field types in MySQL are shared here, I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report