2020-08-27

数据库的基本操作

  1. 创建数据库
    mysql> create database my2020715
    在这里插入图片描述

  2. 删除数据库
    mysql> drop database my2020715;
    在这里插入图片描述

  3. 选择数据库
    mysql> create database my2020715;
    mysql> use my2020715;

在这里插入图片描述

  1. 创建表

在这里插入图片描述

  1. 查看表
    mysql> show tables;
    mysql> desc runoob_tbl;
    在这里插入图片描述

  2. 删除表
    mysql> drop table runoob_tbl;

    对表数据的增,删,改, 查,排序:
    向表内插入数据: insert into 表名(字段) values (字段对应的值);
    mysql> insert into runoob_tbl(runoob_title,runoob_author,submission_date) values (“by”,“ppy”,now());
    now() 函数获取ubuntu 的系统日期。

    查看表的内容: select * from 表名
    mysql> select * from runoob_tbl;

    更新表的数据: update 表名 set 字段 = 新值 where 主键(对应的字段) = 键值;
    mysql> update runoob_tbl set runoob_author = “kitty” where runoob_id = 1002;

    表数据的删除: delete from 表名 where 主键(对应的字段) = 键值;
    mysql> delete from runoob_tbl where runoob_id = 1001;

    查看记录: select * from 表名 where 字段 like ‘字段结尾的相同元素’;
    mysql> select * from runoob_tbl where runoob_author like ‘%y’;

  3. 对表数据的排序:select * from 表名 order by 字段 desc(降序)/asc(升序)
    mysql> select * from runoob_tbl order by runoob_author desc;

在这里插入图片描述

  1. MySQL 里面的alter指令
    删除表字段: alter table 表名 drop 字段;
    mysql> alter table table_1 drop i;

在这里插入图片描述

添加表字段: alter table  表名  add  字段  字段属性
 mysql> alter table table_1 add i int;

在这里插入图片描述

修改表字段:
属性:alter table 表名 modify  字段(已有字段)  属性
mysql> alter table table_1 modify c char(10);

在这里插入图片描述

字段名:alter table 表名 change  字段(已有)  字段  属性 
mysql> alter  table table_1  change i j bigint;

在这里插入图片描述

  1. Mysql 里面两个表的链接

    Inner join : 两个表之间的内部链接:select a.表1字段,a.表1 字段,b.表2字段 from 表1 a inner join 表2 b a.表1字段 = b. 表2字段;
    mysql> select a.c ,a.j ,b.b from table_1 a inner join table_2 b on a.c = b.c;
    在这里插入图片描述

    mysql> SELECT a.c, a.j, b.b FROM table_1 a, table_2 b WHERE a.c = b.c;
    在这里插入图片描述

    Left join:两个表的左链接:
    mysql> select a.c ,a.j ,b.b from table_1 a left join table_2 b on a.c = b.c;
    在这里插入图片描述

    Right join :两个表之间的右链接:
    mysql> select a.c ,a.j ,b.b from table_1 a right join table_2 b on a.c = b.c;
    在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值