入门语句
查看当前服务器下的数据库
show databases;
创建数据库(创建后数据库的名字是不可以更改的)
create database AAA;
create table a
(id int primary key,
name varchar(20),
age tinyint,
sex enum('man','women'),
index (age));
使用某个库
use AAA
创建表
create table worker
(id int primary key, //主键
name varchar(20),
age tinyint,
sex enum('男', '女'),
score double,
level varchar(20) default "NO");
删除表
drop table if exists worker;
查看当前库中的表
show tables;
查看当前所处的是哪个库
select database();
查看当前所在表的建表信息
show create table AAA;
删除库
drop database if exists AAA;
更改表的名字
alter table address rename to addr;
查看表的结构
desc student;
增加
增加多行的部分列
insert into student(name,age,sex,score) //确定表和列
values('liu shuo', 18, '男', 56.7), //确定值
('zhao yun', 24, '女', 95.8);
插入全部列的时候所有列必须都要赋值,包括主键。
insert into student
values(5,'ZWL', 20, '女', 98,'YES');
删除
注意:删除操作的最低标准是一行
delete from student //确定表
where name='liu shuo'; //确定条件
若没有where条件则删除整个表
delete from worker;
查询(单表)
整表查询
select * //所要的内容
from student; //确定查询哪个表
查询满足条件的某列
select name,score //确定列
from student //确定表
where sex='woman'; //确定哪一行
查询满足条件的某行
select *
from student
where score>80;
修改
update student //确定表
set sex='man' //确定要修改的内容
where name='zhao yun'; //确定修改的条件