目录
一、数据库操作 database
1.查看数据库
SHOW DATABASES;
2.创建数据库
CREATE DATABASE 数据库名字 charset='utf8';
3.选择数据库
USE 数据库名字
注意:不要加;
4.删除数据库
drop database 数据库名字;
二、表操作 table
1.查看表
SHOW TABLES;
2.创建表
create | 创建 |
table | 创建的类型 |
student | 表的名字 |
primary key | 主键 |
auto_increment | 自增长 |
int | 整型数 |
char | 字符 |
CREATE TABLE 表名(id INT PRIMARY KEY AUTO_INCREMENT,name CHAR(30),age INT);
create table student(id primary key auto_increment,name char(30),age int);
3.删除表
DROP TABLE 表名;
drop table student;
4.查看表结构
DESC 表名;
desc student;
5.查询
(1)查询当前表中的所有字段的数据
select * from student;
(2)查询当前表中的id,name,age 字段的所有数据
select id,name,age from student;
(3)查询当前的id,name,age,字段的所有数据,并以id正序排列
select id,name,age from student order by id;
(4)查询当前表中type值为"t"的id,name,age字段的所有数据,并以id正序排列
select id,name,age from student where type="t" order by id;
(5)查询当前表中的所有数据,并以id倒序排列
select id,name,age from student order by id desc;
(6)查询当前表中从第二条开始,id,name,age字段的两条数据
select id,name,age from student limit 1,2;
(7)查询当前表中从第三条开始,id,name,age字段的两条数据
select id,name,age from student limit 2,2;