数据库入门到入门哈哈
数据库从入门到入门
建表
create table ss( id int not null primary key Auto_increment comment'学号',
name varchar (20) not null
删除表
drop table ss;
修改表
添加字段:alter table ss add (age int not null);
删除字段:alter table ss drop column age;
修改字段:alter table ss change name age int ;
插入
insert into ss values(1,"kk"),(2,"ll");
查询
普通查询:select * from ss;
条件查询:select * from ss
where id=2;
多表条件查询:select ss.id,ss.age,aa.name from ss,aa
where ss.id=aa.id ;
嵌套查询:select name from aa
where id=(select id from ss
where age=18);
并查询:(select id from ss) union (select id from aa;)
交查询:select id from ss where id in(select id from aa) ;
删除
delete from ss where id =2;
更新
update ss set name="jo"
where id=2;
常用函数
求和:select sum(age) from ss;
平均:select avg(age) from ss;
计数:select count(*) from aa;
字段值唯一:select distinct name from aa;
limit查询结果数限制:select * from ss limit 2;)
排序:select * from ss order by age ;
升序:select * from ss order by age asc ;
降序:select * from ss order by age desc ;
分组:select * from ss group by name ;
索引
普通索引:create ssIndex on ss (name);
唯一索引:create unique index ssIndex on ss (id);
移除索引:drop index ssIndex on ss ;
生活很美好,熬夜不会老
加油!!!
浙公网安备 33010602011771号