mysql基础之增删改查

标签: mysql


增加数据

-- 增加数据
use myblog;
insert into users(username, `password`, realname) values('zhangsan','123','张三');

查询数据

use myblog;
-- 查询表格
show tables;
-- 查询版本
select version();
-- 查询数据
select * from users;
select id, username from users;
-- 查询username='zhangsan'并且password='123'的数据
select * from users where username='zhangsan' and `password`='123';
-- 查询username='zhangsan'或者password='123'的数据
select * from users where username='zhangsan' or `password`='123';
-- 查询password里包含1的数据
select * from users where password like '%1%';
-- 默认是正序 desc是倒序
select * from users where password like '%1%' order by id desc;
-- 不等于
select * from users where password <> 123;

更新数据

use myblog;
update users set realname='李四2' where username='lisi'

删除数据

注:一般很少用,实战中大多都是软删除,通过修改一个标志位来标志当前数据是否可用

use myblog;
delete from users where username='lisi';
原文地址:https://www.cnblogs.com/xwwin/p/13816556.html