Home > Database > Mysql Tutorial > Mysql学习心得之插入、更新、删除记录_MySQL

Mysql学习心得之插入、更新、删除记录_MySQL

WBOY
Release: 2016-06-01 11:52:19
Original
1178 people have browsed it

下面通过图文并茂的方式给大家详解Mysql学习心得之插入、更新、删除记录。

插入记录

代码如下:


Insert[]into] tb1_name[(col_name,…..)]

自动编号的字段,可以用values default

Default 可以赋予默认值

代码如下:


INSERT USERS VALUES(NULL,'TOM','123',25,1);


可以同时插入多条记录

代码如下:


INSERT users VALUES(DEFAULT,'TOM','123',3*7-5,1),(NULL,'ROSE',MD5('123'),DEFAULT,0);


代码如下:


INSERT users SET username='Ben',password='456'; (但只能插入单条记录)

单表更新

代码如下:


UPDATE users SET age =age-id ,sex=0;


代码如下:


UPDATE users SET age=age+10 WHERE id%2=0;

Id%2=0 (id字段除以2的余数为0)

删除字段 delete

代码如下:


DELETE FROM users WHERE id =5;


再插入一条新记录id自动编号为6,而不是已删除的5

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template