MySQL4.索引及视图

server/2024/10/22 2:54:48/

1.建库

create database mydb15_indexstu;
use mydb15_indexstu;

在这里插入图片描述

2.建表

2.1 student表学(sno)号为主键,姓名(sname)不能重名,性别(ssex)仅能输入男或女,默认所在系别(sdept)为’计算机’

create table student( 
sno int primary key auto_increment,
sname varchar(30) not null unique, 
ssex varchar(2) check(ssex='男' or ssex='女') not null, 
sage int not null, 
sdept varchar(10) default'计算机' not null);

在这里插入图片描述

2.2 course表课程号(cno)为主键

create table course( 
cno int primary key not null, 
cname varchar(20) not null);

在这里插入图片描述

2.3 sc表课程号(cno)为主键

create table sc( 
sno int not null,
cno varchar(10) primary key not null, 
score int not null);

在这里插入图片描述

3.实现需求

3.1 修改student表中年龄(sage)字段属性,将数据类型由int改为smallint

alter table student modify sage smallint;

在这里插入图片描述

3.2 为course表中 课程号(cno)字段设置索引,并查看索引

create index cno_index on course(cno);
show create table course\G

在这里插入图片描述

3.3 为sc表建立按学号(sno)和课程号(cno)组合的升序的主键索引,索引名sc_index

create index sc_index on sc(sno,cno asc);
show create table sc\G

在这里插入图片描述

3.4 创建一个视图stu_info,查询全体学生的姓名,性别,课程名,成绩

create view stu_info as select sname,ssex,cname,score from student join sc on student.sno=sc.sno join course on sc.cno=course.cno;
show tables;

在这里插入图片描述

3.5 删除所有索引

drop index cno_index on course;
drop index sc_index on sc;

在这里插入图片描述


http://www.ppmy.cn/server/90154.html

相关文章

Window下安装Zookeeper

一、下载 地址:https://archive.apache.org/dist/zookeeper/zookeeper-3.5.6/ 解压:非中文、没有空格目录下 新建data目录,用于存放数据文件 二、配置 进入conf目录,复制zoo_sample.cfg 为zoo.cfg 打开zoo.cfg 修改dataDir&…

帆软FineReport之替换函数

在日常帆软FineReport中经常会使用字符串替换函数,记录下来,方便备查。 一、字符串替换 第一种、指定文本替换 使用SUBSTITUTE函数,语法如下所示 SUBSTITUTE(text,old_text,new_text,instance_num) 字段…

Python 爬虫入门(一):从零开始学爬虫 「详细介绍」

Python 爬虫入门(一):从零开始学爬虫 「详细介绍」 前言1.爬虫概念1.1 什么是爬虫?1.2 爬虫的工作原理 2. HTTP 简述2.1 什么是 HTTP?2.2 HTTP 请求2.3 HTTP 响应2.4 常见的 HTTP 方法 3. 网页的组成3.1 HTML3.2 CSS3.…

CI/CD学习之路

CI/CD之路 https://mp.weixin.qq.com/mp/appmsgalbum?__bizMzg4NDg0MjQ0MQ&actiongetalbum&album_id3433192036428447744&scene173&subscene&sessionidsvr_0b1e7fe1d6b&enterid1721879847&from_msgid2247485821&from_itemidx1&count3&am…

【Django】网上蛋糕商城后台-商品管理

1.商品管理功能 当管理员点击商品管理时,发送服务器请求 path(admin/goods_list/, viewsAdmin.goods_list), # 处理商品列表请求 def goods_list(request):try:type request.GET["type"]except:type 0try:ym request.GET["ym"]except:ym …

pyaudio VAD通过声音音频值分贝大小检测没人说话自动停止录制

效果可能说话声音小可能不被监听到,需要更改QUIET_DB阈值,另外delay_time值是低于阈值多久就可以停止保存当前的语音 import pyaudio import waveimport sys import numpy as npdef record_auto(MIC_INDEX=1):开启麦克风录音,保存至temp/speech_record.wav音频文件音量超过…

猫头虎分享:Numpy异常 module ‘numpy‘ has no attribute ‘object‘ 解决方案

🐯 猫头虎分享:Numpy异常 module ‘numpy‘ has no attribute ‘object‘ 解决方案 摘要 在这篇文章中,猫头虎将带领大家详细了解并解决 Numpy 异常 module ‘numpy‘ has no attribute ‘object‘。本文将从问题描述、原因分析、解决方案、…

THS配置keepalive(yjm)

启动完THS管理控制台和THS后,登录控制台,进入实例管理》节点管理,可以分别使用界面配置和编辑配置设置长连接。 1、界面配置 点击界面配置》集群设置,启用长连接,设置长连接数、最大请求数和超时时间。 2、编辑配置 …