Home Database Mysql Tutorial mysql光速教程_MySQL

mysql光速教程_MySQL

Jun 01, 2016 pm 01:47 PM
string Tutorial Knowledge points

bitsCN.com

// by redice 2010.07.26
// redice@163.com


为公司实习生写的MYSQL学习提纲,总结了一下在项目开发中用到最多的知识点,可以作为MYSQL快速入门的教程。

1  MYSQL列(字段)数据类型:

(1)字符串类

VARCHAR    可变长度的字符串 高达255字符
    适用于存储用户名,密码,电话号码,邮箱,地址等长度较短(小于255)的字符串

TEXT    没有最大长度限制的可变长度的字符串
    适用于存储文章内容,产品描述,用户留言等长度较大的(大于255)字符串
       

(2)整数类

TINYINT       这个类型最多可容纳三位数
SMALLINT       最多可容纳五位数
MEDIUMINT   最多可容纳八位数
INT       可以容纳十位数
BIGINT       最多可容纳二十位数


(3)小数类

DECIMAL      适用于存储含有小数的数字,例如,产品价格,销售额

DECIMAL(5+3,3)或 DECIMAL(8,3) 表示整数部分最多5位数,小数部分3位数


(4)时间日期类

DATE        以 yyyy-mm-dd格式的日期
TIME        以 hh:mm:ss格式的时间
DATETIME    以yyyy-mm-ddhh:mm:ss格式结合日期和时间,支持的范围为1000-01-01 00:00:00到9999-12-31 23:59:59,8个字节储存,时区转化(改变时区,显示不改变)
TIMESTAMP    以yyyy-mm-ddhh:mm:ss格式结合日期和时间,值不能早于1970或晚于2037,4个字节储存,与时区无关(改变时区,显示自动调整)

说明:可将时间日期类当做特殊的字符串类看待。

2 MYSQL常用的内置函数

(1)字符处理类

ASCII(str)        返回字符串str的第一个字符的ASCII值(str是空串时返回0)
CHAR(N,...)    返回由参数N,...对应的ASCII代码字符组成的一个字串(参数是N,...是数字序列,NULL值被跳过)
CONCAT(str1,str2,...)    把参数连成一个长字符串并返回(任何参数是NULL时返回NULL)
REPLACE(str,from_str,to_str)     用字符串to_str替换字符串str中的子串from_str并返回
UCASE(str) 或 UPPER(str)         返回大写的字符串str
CHAR_LENGTH(str)    返回字符串str的字符数(对于多字节字符仅计算一次)
LENGTH(str)或OCTET_LENGTH(str)    返回字符串str的字节数(对于多字节字符按字节数计算)

(2)时间日期类

CURDATE()        以YYYY-MM-DD格式返回当前日期值,返回字符串值
CURTIME()        以HH:MM:SS格式返回当前时间值(根据返回值所处上下文是字符串或数字),返回字符串值
NOW()         以YYYY-MM-DD HH:MM:SS格式返回当前日期时间,返回字符串值
UNIX_TIMESTAMP(datetimestr)     返回一个Unix时间戳(从1970-01-01 00:00:00GMT开始的秒数,datetimestr默认值为当前时间),返回整数值
FROM_UNIXTIME(unix_timestamp) 以YYYY-MM-DD HH:MM:SS格式返回时间戳的值,返回字符串值

提示:为了加速查询速度,大型系统通常把时间日期的时间戳值以INT(10)的格式存储。


3 SQL语句

SQL语句中,单引号来环绕文本(字符串)值,例如 redice  文本中含有单引号需要转义,例如 redices blog

如果是数值,不要使用引号

时间日期类型按文本(字符串)对待

(1)SELECT

SELECT 列名(字段名) FROM 表名称  WHERE 查询条件

聚合函数:
AVG(column),COUNT(column),MAX(column),MIN(column),SUM(column)

(2)DELETE

DELETE FROM 表名称 WHERE 查询条件

(3)INSERT

INSERT INTO 表名称 (列1, 列2,...) VALUES (值1, 值2,....)

例如:
insert into user (name,pass,age,regtime) values (redice,123456,24,now())

(4)UPDATE

UPDATE 表名称 SET 列1 = 值1,列2 = 值2,.... WHERE 查询条件

本文参考了w3school的部分文章: asp">http://www.w3school.com.cn/sql/index.asp

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tutorial on how to use Dewu Tutorial on how to use Dewu Mar 21, 2024 pm 01:40 PM

Dewu APP is currently a very popular brand shopping software, but most users do not know how to use the functions in Dewu APP. The most detailed usage tutorial guide is compiled below. Next is the Dewuduo that the editor brings to users. A summary of function usage tutorials. Interested users can come and take a look! Tutorial on how to use Dewu [2024-03-20] How to use Dewu installment purchase [2024-03-20] How to obtain Dewu coupons [2024-03-20] How to find Dewu manual customer service [2024-03-20] How to check the pickup code of Dewu [2024-03-20] Where to find Dewu purchase [2024-03-20] How to open Dewu VIP [2024-03-20] How to apply for return or exchange of Dewu

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

Tutorial on how to turn off the payment sound on WeChat Tutorial on how to turn off the payment sound on WeChat Mar 26, 2024 am 08:30 AM

1. First open WeChat. 2. Click [+] in the upper right corner. 3. Click the QR code to collect payment. 4. Click the three small dots in the upper right corner. 5. Click to close the voice reminder for payment arrival.

What software is photoshopcs5? -photoshopcs5 usage tutorial What software is photoshopcs5? -photoshopcs5 usage tutorial Mar 19, 2024 am 09:04 AM

PhotoshopCS is the abbreviation of Photoshop Creative Suite. It is a software produced by Adobe and is widely used in graphic design and image processing. As a novice learning PS, let me explain to you today what software photoshopcs5 is and how to use photoshopcs5. 1. What software is photoshop cs5? Adobe Photoshop CS5 Extended is ideal for professionals in film, video and multimedia fields, graphic and web designers who use 3D and animation, and professionals in engineering and scientific fields. Render a 3D image and merge it into a 2D composite image. Edit videos easily

Experts teach you! The Correct Way to Cut Long Pictures on Huawei Mobile Phones Experts teach you! The Correct Way to Cut Long Pictures on Huawei Mobile Phones Mar 22, 2024 pm 12:21 PM

With the continuous development of smart phones, the functions of mobile phones have become more and more powerful, among which the function of taking long pictures has become one of the important functions used by many users in daily life. Long screenshots can help users save a long web page, conversation record or picture at one time for easy viewing and sharing. Among many mobile phone brands, Huawei mobile phones are also one of the brands highly respected by users, and their function of cropping long pictures is also highly praised. This article will introduce you to the correct method of taking long pictures on Huawei mobile phones, as well as some expert tips to help you make better use of Huawei mobile phones.

Detailed explanation of the method of converting int type to string in PHP Detailed explanation of the method of converting int type to string in PHP Mar 26, 2024 am 11:45 AM

Detailed explanation of the method of converting int type to string in PHP In PHP development, we often encounter the need to convert int type to string type. This conversion can be achieved in a variety of ways. This article will introduce several common methods in detail, with specific code examples to help readers better understand. 1. Use PHP’s built-in function strval(). PHP provides a built-in function strval() that can convert variables of different types into string types. When we need to convert int type to string type,

How to repeat a string in python_python repeating string tutorial How to repeat a string in python_python repeating string tutorial Apr 02, 2024 pm 03:58 PM

1. First open pycharm and enter the pycharm homepage. 2. Then create a new python script, right-click - click new - click pythonfile. 3. Enter a string, code: s="-". 4. Then you need to repeat the symbols in the string 20 times, code: s1=s*20. 5. Enter the print output code, code: print(s1). 6. Finally run the script and you will see our return value at the bottom: - repeated 20 times.

PHP Tutorial: How to convert int type to string PHP Tutorial: How to convert int type to string Mar 27, 2024 pm 06:03 PM

PHP Tutorial: How to Convert Int Type to String In PHP, converting integer data to string is a common operation. This tutorial will introduce how to use PHP's built-in functions to convert the int type to a string, while providing specific code examples. Use cast: In PHP, you can use cast to convert integer data into a string. This method is very simple. You only need to add (string) before the integer data to convert it into a string. Below is a simple sample code

See all articles