学习和回顾mysql01的基本语句。增删改查,多表关联,索引

1.增删改查

创建数据库database2020;
create database database2020;
创建一个最简单的表。
create table tr(a int );
create table student(stu int no null auto_invrement(自动增长) ,primary key(stu));创建主键。
查询student表的信息
select * from student;
插入一条数据,表(属性)+(值)insert into table ()values();
insert into t_user (age,name)values(12,‘waner’);
更新数据,stuid=1的记录,改age=100
update table set age=10 where stuid=1 ;
update student set age=100 where stuid=1;
更新数据,stuid=2的记录,改name=‘ligang’ ,age=10
update table set name=‘I love you’ where stuid=2;
update student set name=‘ligang’ ,age=10 where stuid=2;
删除stuid=2的记录
delete from student where stuid=2;

2.多表关联

主键表是一个,外键与多个(一对多的关联)
设置主键:Primary key(teaid)
设置外键:foreign key(teaid) references teacher2(teaid)
多表之间的关联是通过关联的字段来实现的。两种方式:
弱关联:没有设置外键。用于互联网上
强关联:设置外键。企业内部

3.索引

用索引提高查询的速度,利用索引提高数据库的性能 。(字典效果)
Create index 索引名 on 表名
drop index 索引名 on 表名
create index index1 on teacher(name);
drop index index1 on teacher1
create unique index 索引名 on 表名(字段名)不允许索引的字段值重复

场景:
数据量大,查询多。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值