mysql数据库的简单操作

xiaoxiao2021-02-28  84

在虚拟机中的操作

1.  sqlite3  text.db(文件名) 没有则自动创建

2.   .tables  查看表

3. 创建表

create table student (

ID        INTERGER,

name TEXT,

sex     TEXT,

age    INTEGER,

primary  key(ID)                               //表示ID不可重复,自己运行一下就知道了

);

create table score(

ID           INTERGER,

score     TEXT,

subject  INTERGER,

);

4.  插入

insert into student values ( 1, 'zhang' , ' M ' , 18 );      // 分号不要忘记

5.  删除表

drop tables student         //删除表名为student 的表

6.  修改表信息

update name set name='sun'  where  name = 'zhang' (原来);

7. 删除表信息

delete from name where name = 'sun';

8. 单表查询

select  ID,name from student sex = 'M';

select *from score where score<80  ;                         // (这里是另一个表中包含score)   *from 查询结果出现所有字段

select  distinct *from score                                              //查询结果没有重复记录 

9. 查询结果按某个字段的值进行排序

select *from score order by ID asc ;                          //  asc 分数由低到高

select *from score order by ID desc;                          // desc  由高到低

10.  多表联合查询

select  student.name from stdent,score where student.ID = score.ID and score.score>80;

//ID相同且分数大于80 的学生姓名

转载请注明原文地址: https://www.6miu.com/read-84689.html

最新回复(0)