SQL TEXT Date and set data types in MySQL

Source: Internet
Author: User

The MySQL data table fields must have a data type defined. There are about 25 options, most of which are straightforward, and it's not much of a waste of breath. But there are a few that need to be mentioned.

TEXT is not a data type, although it may be said in some books. It should actually be "LONG VARCHAR" or "Mediumtext".

The format of the date data type is YYYY-MM-DD, for example: 1999-12-08. You can easily use the date function to get the current system time in this format:

Date ("y-m-d")

Also, you can subtract between the data types to get the difference in the number of days:

$age = ($current _date-$birthdate);

Set set is a useful data type and is somewhat similar to enum enum, except that a set can hold multiple values and an enum can only hold one value. Also, a SET type can have up to 64 predetermined values, whereas an ENUM type can handle up to 65,535 predefined values. And what if you need a collection of more than 64 values? Then you need to define multiple sets to solve the problem together.

Wildcard characters

There are two types of identical characters for SQL: "*" and "%". Used in different situations respectively. For example: If you want to see all of the contents of a database, you can query like this:

SELECT * FROM dbname

WHERE user_id like '% ';

Here, two wildcard characters have been used. Do they mean the same thing? are used to match any of the strings, but they are used in different contexts. "*" is used to match field names, and "%" is used to match field values. Another area that is not easily noticed is that the% wildcard character needs to be used in conjunction with the LIKE keyword.

There is also a wildcard, which is the underscore "_", which means different from the above, is used to match any single character.

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.