Mysql 增减查询基本语句
2017-06-29 07:21
633 查看
MySQL增删改查语句
select * from xxx;
insert into xxx values();
update xxx set xx=xx where xxx=xxx and xxx=xxx;
delete from xxx where xx=xxx and xxx=xxx or……;
MySQL基本语句(增删改查,like语句)
查询:
select 字段名 from 表名;
例1:select * from tablename;//查询全部
例2:select (id,name) from tablename;//查询id,name
例3:select id as studentID from tablename;//查询id,查询出来的表的本来的字段名id变为studentID,as可省略
PS:查询时注意*好不能乱用,否则会导致数据库运行负担。最好是需要什么字段就查询什么字段
增添:
insert into tablename value(xx,xx);
例1:insert into tablename(id,name) value (xx,xx);//增加一行数据,只写了id与name
例2:insert into tablename value();//增加一行数据,括号里写全部信息,用逗号隔开
修改:
update tablename set xx=xx where xx=xx;
例1:updete tablename set id=1 where name="董磊";把name为董磊的id更改为1
例2:updete tablename set id=1 where name="董磊" or iq<10;
把name为董磊或者IQ<10的id更改为1。条件用and、or连接
删除:
delete from tablename where xx=xxx;
例1:delete from tablename;//删除表
例2:delete from tablename where id=1;//把id为1的数据删掉
like语句:
// %代表0到多个字符
// _代表一个字符
例: selcet name from student where name like '张%'//查询student表中name以张开头的人的name
selcet name from student where name like '张_'//查询student表中name以张开头的2个字的name
select * from xxx;
insert into xxx values();
update xxx set xx=xx where xxx=xxx and xxx=xxx;
delete from xxx where xx=xxx and xxx=xxx or……;
MySQL基本语句(增删改查,like语句)
查询:
select 字段名 from 表名;
例1:select * from tablename;//查询全部
例2:select (id,name) from tablename;//查询id,name
例3:select id as studentID from tablename;//查询id,查询出来的表的本来的字段名id变为studentID,as可省略
PS:查询时注意*好不能乱用,否则会导致数据库运行负担。最好是需要什么字段就查询什么字段
增添:
insert into tablename value(xx,xx);
例1:insert into tablename(id,name) value (xx,xx);//增加一行数据,只写了id与name
例2:insert into tablename value();//增加一行数据,括号里写全部信息,用逗号隔开
修改:
update tablename set xx=xx where xx=xx;
例1:updete tablename set id=1 where name="董磊";把name为董磊的id更改为1
例2:updete tablename set id=1 where name="董磊" or iq<10;
把name为董磊或者IQ<10的id更改为1。条件用and、or连接
删除:
delete from tablename where xx=xxx;
例1:delete from tablename;//删除表
例2:delete from tablename where id=1;//把id为1的数据删掉
like语句:
// %代表0到多个字符
// _代表一个字符
例: selcet name from student where name like '张%'//查询student表中name以张开头的人的name
selcet name from student where name like '张_'//查询student表中name以张开头的2个字的name
相关文章推荐
- MYSQL基本查询语句练习2--GROUP BY HAVING COUNT 查找分数表中一个学生同一课程有两条数据
- MySQL基本SQL语句之单表查询、多表查询和子查询
- MySQL(4):CRUD语句(2)——基本查询
- MySQL基本查询语句
- <转>MySQL查询语句练习题,测试基本够用了
- MySQL基本查询语句练习
- MySQL基本查询语句
- mysql基本查询语句review
- 跟王老师学MySQL: 基本查询语句
- MySQL表格查询基本语句2
- MySQL基本SQL语句之单表查询、多表查询和子查询
- MySQL中的基本查询语句学习笔记
- mysql去除重复查询的SQL语句基本思路
- mysql基本查询语句review-2
- Mysql多表查询 --一个例子基本搞通mysql语句
- mysql的基本查询语句
- MySQL中的基本查询语句学习笔记
- MySQL查询语句练习题,基本够用了
- MYSQL基本查询语句DQL