MySQL数据库的基础操作
来源:互联网 发布:java aspose 乱码 编辑:程序博客网 时间:2024/05/27 16:43
1.插入数据: 命令:insert into <表名> 【(字段名1).....】values (值n)
insert into test (id, name) values(1,'xiaozhang');
插入id为1,name为xiaozhang的表。
insert into test(id,name) values (2,‘xiaoyu’),(3,xiaoli);
批量插入方法,提升效率。
2.查询数据:命令: select <字段1,字段2,....> from <表名> where<表达式>
select * from test;
查看表test中的所有数据,一般不推荐这样查询,拖慢效率。
select * from test limit 2;
查询最前面的两行数据。
select * from test order by id desc limit 0,2;
select * from test order by id asc limit 0,2;
以id查询表的第0到2行,desc降序,asc升序。
select * from test order where id =2;
select * from test order where name =' xiaozhang';
3.修改表中的数据: 命令:update 表名 set 字段=新值,.... where 条件
update test set name='xiaoyu' where id =1;
把id为1的值的name中的内容修改为xiaoyu。
update test set name='xiaoyu' where name='xiaoli' ;
update test set name='xiaoyu' ;
把name这项的内容全部改为xiaoyu.
4.删除表中的数据:命令:delete from 表名 where 表达式
delete from test where id=1;
删除表test中编号为1的记录。
delete * from test;
删除表中的所有数据。
5.在表中增删改字段: 命令:alter table 表名 add 字段 类型 其他;
alter table test add sex char (4);
增加性别列sex。
alter table test add age int(4) after name;
在name列后增加age列。
6.清空表中的内容:命令:truncate table 表名;
truncate table test;
清空表中的所有内容。
7.更改表名:命令:rename table 原表名 to 新表名;
rename table test to mysyu;
更改表名为mysyu。
8.删除表:命令:drop table <表名>
drop table test;
删除表名为test的表。
- Mysql数据库的基础操作
- MySQL数据库的操作基础
- MySQL数据库的基础操作
- mysql数据库基础操作
- MySQL数据库操作基础
- MySql数据库基础操作
- Mysql数据库基础操作
- MySQL基础2---数据库的基本操作
- mysql数据库的基础操作sql应用
- MySQL数据库索引的基础操作
- 整理MySQL数据库的基础操作
- MySQL数据库的基础操作--例子
- 一些基础的MySQL数据库操作语句
- mysql数据库基础--数据库操作
- MySQL 数据库基础操作类
- python-基础-操作mysql数据库
- MySQL基础-数据库基本操作
- 【MySQL】数据库操作基础笔记
- 云计算教程-翻译(1)
- 公钥、私钥和数字证书
- android-app Administration and Device Administration
- 线程同步与互斥
- mongodb在document存在时update不存在时save
- MySQL数据库的基础操作
- 中文配置filter
- 关于 esayui表格获取数据报错No result defined for action *** and result input
- Intent
- lemon git
- 控制台留言板,主要实现文件操作的功能
- this install package could not be opened. verify that the package exists and that you can ac
- 运动会计分系统(试运行版)
- 【LEETCODE】172-Factorial Trailing Zeroes