MySQL light speed tutorial

Source: Internet
Author: User
MySQL light speed tutorial


Date: 2010-07-29|
Source: redice's blog|
Author: redice|
167 onlookers|
0 people applaud!

// By redice 2010.07.26
// Redice@163.com

The MySQL Learning Outline for the company intern summarizes the most useful knowledge points in project development and can be used as a MySQL quick start tutorial.

1 MySQL column (field) Data Type:

(1) String

Varchar variable-length string up to 255 characters
It is applicable to strings with a short length (less than 255), such as user name, password, phone number, email address, and address.

Text strings with no maximum length limit
Suitable for storageArticleContent, product description, user messages, and other long (more than 255) strings

(2) Integer

Tinyint can contain up to three digits.
Smallint can accommodate up to five digits
Mediumint can accommodate up to eight digits
Int can contain ten digits
Bigint can accommodate up to 20 digits

(3) decimal class

Decimal is suitable for storing decimal numbers, such as product prices and sales.

Decimal (5 + 3, 3) or decimal (8, 3) indicates that the integer part can be at most 5 digits, and the decimal part can be 3 digits.

(4) time and date

Date in yyyy-mm-dd format
Time in HH: mm: SS format
Datetime combines the date and time in the format of yyyy-mm-DDHH: mm: Ss. The supported range is '2017-01-01 00:00:00 'to '2017-12-31 23:59:59 ', 8-byte storage, time zone conversion (change the time zone, the display does not change)
Timestamp combines the date and time in the format of yyyy-mm-DDHH: mm: Ss. The value cannot be stored before 1970 or later than 2037,4 bytes, and is irrelevant to the time zone (change the time zone and display automatic adjustment)

Note: the time and date classes can be viewed as special string classes.

2. Common MySQL built-in functions

(1) character processing class

ASCII (STR) returns the ASCII value of the first character of the string STR (0 is returned when STR is an empty string)
Char (n,...) returns the ASCII value corresponding to the parameter n ,...CodeA string composed of characters (the parameter is N,... is a numerical sequence, and the null value is skipped)
Concat (str1, str2,...) Concatenates the parameter into a long string and returns (if any parameter is null, null is returned)
Replace (STR, from_str, to_str) replaces the child string from_str with the to_str string and returns
Ucase (STR) or upper (STR) returns an uppercase string Str
Char_length (STR) returns the number of characters in the STR string (only once for multi-byte characters)
Length (STR) or octet_length (STR) returns the number of bytes of the STR string (calculated by the number of bytes for multi-byte characters)

(2) time and date

Curdate () returns the current date value in 'yyyy-MM-DD 'format, returns the string value
Curtime () returns the current time value in the format of 'hh: mm: ss' (the context of the returned value is a string or number) and returns the string value.
Now () returns the current date and time in 'yyyy-MM-DD hh: mm: ss' format, returns the string value
Unix_timestamp (datetimestr) returns a Unix timestamp (the number of seconds since '2017-01-01 00:00:00 'GMT, and datetimestr defaults to the current time) and returns an integer.
From_unixtime (unix_timestamp) returns the timestamp value in 'yyyy-MM-DD hh: mm: ss' format and returns the string value

Tip: To accelerate the query speed, large systems usually store the timestamp value of time and date in int (10) format.

3. SQL statement

In SQL statements, single quotes enclose text (string) values. For example, 'redic' text contains single quotes that need to be escaped. For example, 'redics' blog'

Do not use quotation marks for numeric values.

Time and date types are treated by text (string)

(1) Select

Select column name (field name) from table name where query Condition

Aggregate functions:
AVG (column), count (column), max (column), min (column), sum (column)

(2) Delete

Delete from table name where query Condition

(3) Insert

Insert into Table Name (column 1, column 2,...) values (value 1, value 2 ,....)

For example:
Insert into user (name, pass, age, regtime) values ('redic', '123456', 24, now ())

(4) Update

Update table name set column 1 = value 1, column 2 = value 2,... where query Condition

This article references part of w3school: http://www.w3school.com.cn/ SQL /index.asp

Related Article

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.