当前位置: 首页 > news >正文

数据库第四次实验

目录

1.建立数据表并插入数据

2 视图的创建

2.1 行列子集视图的创建

2.2 多表视图

2.3视图上建立视图

2.4分组视图

2.5带表达式的视图

3 删除视图

​​​​​​​​​​​​​​4 查询视图

​​​​​​​5 更新视图

5.1 修改某一个属性

5.2 删除一条数据

5.3 插入一条数据

​​​​​​​6 索引

6.1建立索引

6.2修改索引

6.3删除索引


1.建立数据表并插入数据

SQL语句:

create database ExperimentFour;
use ExperimentFour;

create table Student4
(
   Sno char(2) not null,
   Sname varchar(20) not null,
   Ssex char(2) not null,
   constraint s2 check(Ssex in('', '')),
   Sage int not null,
   constraint s3 check (Sage between 0 and 130),
   Department varchar(20) not null
);

create table Course4
(
   Cno char(2) not null ,
   Cname varchar(20) not null,
   Cprepare varchar(20) not null,
   Ccredit float not null,
   constraint c3 check(0 < Ccredit)
);

create table SC4
(
   Sno char(2) not null,
   Cno char(2) not null,
   Performance float not null,
   constraint sc1 check(Performance between 0 and 100)
);

insert into student4(sno, sname, ssex, sage, department)
values (21, '张三', '', 18, '计通学院'),
       (04, '李四', '', 19, '化学院'),
       (02, '翠花', '', 18, '文新学院');

insert into course4(cno, cname, cprepare, ccredit)
values (11, '概率论', '高等数学', 3),
       (12, '数字电路', '离散结构', 2.5),
       (13, '数据结构', '离散结构', 3.5),
       (01, '嵌入式', '数字电路', 2);

insert into sc4(sno, cno, performance)
values (21, 11, 66),
       (02, 01, 89),
       (04, 12, 59);

截图:

视图的创建

2.1 行列子集视图的创建

SQL语句:

use experimentfour;

create view ComputerStudent
as
select Sname, Sno, Sage
from student4
where Department = '计通学院'
with check option;

select *
from ComputerStudent;

截图:

2.2 多表视图

SQL语句:

use experimentfour;

create view Chinese_S1(Sno, Sname, Performance)
as
select student4.Sno, Sname, Performance
from student4, sc4
where Department = '文新学院' and student4.Sno = sc4.Sno and sc4.Cno = 1;

select *
from Chinese_S1;

截图:

2.3视图上建立视图

SQL语句:

use experimentfour;

create view GoodStudent(Sno, Sname)
as
select Sno, Sname
from chinese_s1
where Performance > 80;

select *
from GoodStudent;

截图:

2.4分组视图

SQL语句:

use experimentfour;

create view S_G(Sno, Performance)
as
select Sno, AVG(Performance)
from sc4
group by Sno;

select *
from S_G;

截图:

2.5带表达式的视图

SQL语句:

use experimentfour;

create view BT_S(Sno, Sname, Birth)
as
select Sno, Sname, 2023 - Sage
from student4;

select *
from BT_S;

截图:

​​​​​​​3 删除视图

SQL语句:

use experimentfour;

drop view goodstudent;

截图:

​​​​​​​​​​​​​​4 查询视图

SQL语句:

use experimentfour;

select Sno, Performance
from s_g
where Performance > 60;

截图:

​​​​​​​5 更新视图

5.1 修改某一个属性

SQL语句:

use experimentfour;

update computerstudent
set Sname = '沸羊羊'
where Sno = 21;

select *
from computerstudent;

截图:

5.2 删除一条数据

SQL语句:

use experimentfour;

delete
from computerstudent
where Sno = 21;

select *
from computerstudent;

截图:

5.3 插入一条数据

SQL语句:

use experimentfour;

create view student
as
select * from student4;

insert into student
values (10, '李明', '', 20, '能动学院');

select * from student;

截图:

​​​​​​​6 索引

6.1建立索引

SQL语句:

use experimentfour;

create unique index Stusno on Student4(Sno);
create unique index Coucno on Course4(Cno);
create unique index SCno on SC4(Sno ASC, Cno DESC);

6.2修改索引

SQL语句:

use experimentfour;

alter table sc4 rename index SCno to SCSno;

6.3删除索引

SQL语句:

use experimentfour;

drop index Stusno on student4;

http://www.lryc.cn/news/301771.html

相关文章:

  • 基于PPNSA+扰动算子的车间调度最优化matlab仿真,可以任意调整工件数和机器数,输出甘特图
  • UnityShader——06UnityShader介绍
  • 人工智能学习与实训笔记(一):零基础理解神经网络
  • LeetCode刷题小记 一、【数组】
  • iOS总体框架介绍和详尽说明
  • 【C++】const与constexpr详解
  • 蓝桥杯:日期统计讲解(C++)
  • Python re.findall()中的正则表达式包含多个括号时的返回值——包含元组的列表
  • Python——列表
  • 无人机图像识别技术研究及应用,无人机AI算法技术理论,无人机飞行控制识别算法详解
  • 清华AutoGPT:掀起AI新浪潮,与GPT4.0一较高下
  • 人工智能学习与实训笔记(二):神经网络之图像分类问题
  • SSM框架,spring-aop的学习
  • 【设计模式】4、策略模式
  • 【C++学习手札】多态:掌握面向对象编程的动态绑定与继承机制(深入)
  • 【机构vip教程】Android SDK手机测试环境搭建
  • 2024.2.18
  • Haproxy实验
  • CSRNET图像修复,DNN
  • 004 - Hugo, 分类
  • Vue3之ElementPlus中Table选中数据的获取与清空方法
  • Leetcode 516.最长回文子序列
  • cool Node后端 中实现中间件的书写
  • Leecode之面试题消失的数字
  • STM32的三种下载方式
  • 华为 huawei 交换机 接口 MAC 地址学习限制接入用户数量 配置示例
  • 使用Python生成二维码的完整指南
  • 排序前言冒泡排序
  • 红队笔记Day3-->隧道上线不出网机器
  • C 练习实例70-求字符串长度