«

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

时间:2024-3-1 23:03     作者:韩俊     分类: Mysql


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

插入记录

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

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

Default 可以赋予默认值

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

Notice: Undefined index: CMSdown in /data/webroot/gcms/lib/Api/Open/Article.php on line 161
img/2015/08/19/142115_55d4205b84a23.png" alt="查看图片" />

Notice: Undefined index: CMSdown in /data/webroot/gcms/lib/Api/Open/Article.php on line 161
img/2015/08/19/142115_55d4205be8968.png" alt="查看图片" />

可以同时插入多条记录

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

Notice: Undefined index: CMSdown in /data/webroot/gcms/lib/Api/Open/Article.php on line 161
img/2015/08/19/142116_55d4205c536cf.png" alt="查看图片" />

方法2

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

Notice: Undefined index: CMSdown in /data/webroot/gcms/lib/Api/Open/Article.php on line 161
img/2015/08/19/142117_55d4205d22f74.png" alt="查看图片" />

单表更新

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

Notice: Undefined index: CMSdown in /data/webroot/gcms/lib/Api/Open/Article.php on line 161
img/2015/08/19/142117_55d4205d6b9f0.png" alt="查看图片" />

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

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

Notice: Undefined index: CMSdown in /data/webroot/gcms/lib/Api/Open/Article.php on line 161
img/2015/08/19/142118_55d4205e16e29.png" alt="查看图片" />

删除字段 delete

DELETE FROM users WHERE id =5;

Notice: Undefined index: CMSdown in /data/webroot/gcms/lib/Api/Open/Article.php on line 161
img/2015/08/19/142118_55d4205ea8eb3.png" alt="查看图片" />

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

Notice: Undefined index: CMSdown in /data/webroot/gcms/lib/Api/Open/Article.php on line 161
img/2015/08/19/142119_55d4205f15f14.png" alt="查看图片" />

标签: mysql

热门推荐