首页 > 数据库 >数据库第十一次作业-视图的应用【带源码】

数据库第十一次作业-视图的应用【带源码】

时间:2022-10-14 17:31:32浏览次数:65  
标签:varchar 第十一次 sign 视图 mark stu 源码 null id


目录

​1.创建表​

​2.添加数据​

​3.查看数据​

​4.创建视图​


 

1.创建表

数据库第十一次作业-视图的应用【带源码】_添加数据

create table stu(

    -> s_id int(11) not null unique primary key,

    -> s_name varchar(20) not null,

    -> addr varchar(50) not null,

    -> tel varchar(50) not null

-> );

create table sign(

    -> s_id int(11) not null unique primary key,

    -> s_name varchar(20) not null,

    -> s_sch varchar(50) not null,

    -> s_sign_sch varchar(50) not null

    -> );

create table stu_mark(

    -> s_id int(11) not null unique primary key,

    -> s_name varchar(20) not null,

    -> mark int(11) not null

    -> );

数据库第十一次作业-视图的应用【带源码】_数据库_02

2.添加数据

数据库第十一次作业-视图的应用【带源码】_sql_03

数据库第十一次作业-视图的应用【带源码】_数据库_04

insert into stu values

    -> (1,"ZhangPeng","Hebei",13889075861),

    -> (2,"LiXiao","Shandong",13953508223),

    -> (3,"HangYun","Shandong",13905350996);

insert into sign values

    -> (1,"ZhangPeng","High_School1","Peking_University"),

    -> (2,"LiXiao","High_School2","Peking_University"),

    -> (3,"HuangYun","High_School3","Tsinghua_University");

insert into stu_mark values

    -> (1,"ZhangPeng",730),

    -> (2,"LiXiao",725),

    -> (3,"HuangYun",736);

数据库第十一次作业-视图的应用【带源码】_sql_05

数据库第十一次作业-视图的应用【带源码】_mysql_06

3.查看数据

数据库第十一次作业-视图的应用【带源码】_数据库_07

数据库第十一次作业-视图的应用【带源码】_database_08

4.创建视图

数据库第十一次作业-视图的应用【带源码】_sql_09

create view beida as

    -> select a.s_id,a.s_name,c.mark,b.s_sign_sch from

    -> stu a inner join stu_mark c on  a.s_id = c.s_id

    -> inner join sign b on c.s_id = b.s_id where

    -> c.mark>=720 and

    -> b.s_sign_sch ="Peking_University";

数据库第十一次作业-视图的应用【带源码】_数据库_10

数据库第十一次作业-视图的应用【带源码】_数据库_11

create view qinghua as

    -> select a.s_id,a.s_name,c.mark,b.s_sign_sch from

    -> stu a inner join stu_mark c on  a.s_id = c.s_id

    -> inner join sign b on c.s_id = b.s_id where

    -> c.mark>=725 and

    -> b.s_sign_sch ="Tsinghua_University";

数据库第十一次作业-视图的应用【带源码】_数据库_12

数据库第十一次作业-视图的应用【带源码】_sql_13

update stu_mark set

    -> mark=mark-10

    -> where stu_mark.s_name ="HuangYun";

数据库第十一次作业-视图的应用【带源码】_添加数据_14

标签:varchar,第十一次,sign,视图,mark,stu,源码,null,id
From: https://blog.51cto.com/u_15829839/5757566

相关文章