当前位置:网站首页>[database] must know at the end of the term ----- Chapter 6 experiment
[database] must know at the end of the term ----- Chapter 6 experiment
2022-07-19 04:08:00 【Lambs can't fly】
Chapter six Experimental part
( This part is the focus of the exam )
1、SQL The composition of language 、 characteristic ?
form :
1)DDL( Database definition language :CREAT、DROP、ALTER)
2)DML( Database manipulation language :INSERT、UPDATE、DELETE、SELECT)
3)DCL( Database control language :GRANT、REVOKE)
characteristic :
Integrate and unify 、 Highly unprocessed 、 Face the set 、 The language is simple 、 Easy to learn and easy to learn
2、 Write SQL Data definition statement ( Create delete database 、 Data sheet 、 Will modify the table structure )?
// Create database
CREATE DATABASE D1;
// Delete database
DROP DATABASE D1;
// Create table
CREATE TABLE student(
Student number char(4) NOT NULL PRIMARY KEY,
full name char(8) NOT NULL,
Gender char(2),
Date of birth date,
Home address varchar(50)
);
// Delete table
DROP TABLE student;
// Modify table structure
ALTER TABLE grade
ADD CONSTRAINT fk1 FOREIGN KEY( Student number ) REFERENCES student( Student number );
ALTER TABLE grade
ADD CONSTRAINT fk2 FOREIGN KEY( Course number ) REFERENCES curriculum( Course number );
ALTER TABLE student
ADD remarks varchar(50);
.......3、 Write SQL Inquire about ( The basic query 、 How to write the conditions ; nested queries 、 Link query 、 Set query ;order by、 group by, Aggregate functions should be able to )?
// The basic query
SELECT Student number , full name , Date of birth FROM student;
SELECT full name , Home address FROM student WHERE Student number ='0002';
SELECT full name , Date of birth FROM student
WHERE Date of birth >='2001-01-01' and Gender =' Woman ';
// Conditions of the query
SELECT * FROM grade WHERE fraction BETWEEN 70 AND 80;
SELECT AVG( fraction ) average FROM grade WHERE Course number ='0002';
SELECT COUNT(*) The number of students who choose courses ,COUNT( fraction ) The number of people with achievements FROM grade WHERE Course number
='0003';
SELECT full name , Date of birth FROM student WHERE Home address LIKE ' Hangzhou %'ORDER BY born
date DESC;
SELECT Student number , full name FROM student WHERE full name LIKE ' Zhang %'
// nested queries
(
1)
SELECT full name , Date of birth FROM student
WHERE Gender =(SELECT Gender FROM student WHERE full name =' Liu Dongyang ');
(
2)
SELECT Student number , full name , Gender FROM student
WHERE Student number IN(SELECT Student number FROM grade
WHERE Course number IN ('0002','0005'));
(
3)
SELECT Course number , fraction FROM grade
WHERE Student number ='0001' and fraction >ANY(SELECT fraction FROM grade
WHERE Student number ='0002');
(
4)
SELECT Course number , fraction FROM grade
WHERE Student number ='0001' and fraction >ALL(SELECT fraction FROM grade
WHERE Student number ='0002');
// Link query
(
1)SELECT s. Student number , full name , fraction FROM student s,grade g
WHERE s. Student number =g. Student number and fraction BETWEEN 80 AND 90;
(
2)
SELECT s. Student number , full name , fraction FROM student s INNER JOIN grade g
ON s. Student number =g. Student number INNER JOIN curriculum c ON g. Course number =c. Course number
WHERE Course name =' Database principle and Application ';
or
SELECT s. Student number , full name , fraction FROM student s , grade g,curriculum c
WHERE s. Student number =g. Student number and g. Course number =c. Course number
and Course name =' Database principle and Application ';
(
3)
SELECT s. Student number , full name ,MAX( fraction ) Top grade
FROM student s,grade g
WHERE s. Student number =g. Student number
GROUP BY s. Student number ;
(
4)
SELECT s. Student number , full name ,SUM( fraction ) Total score
FROM student s LEFT OUTER JOIN grade g ON s. Student number =g. Student number
GROUP BY s. Student number ;
notes :outer Don't write .
(
5)
insert into curriculum values('0006', 'Python', 3);
INSERT INTO grade VALUES('0004','0006',76);
SELECT g. Course number , Course name ,count( Student number ) Number of electives
FROM grade g RIGHT OUTER JOIN curriculum c ON g. Course number =c. Course number
GROUP BY g. Course number ; 4、 Be able to write SQL Data update statement ( Insert 、 modify 、 Delete )?
// Insert
INSERT INTO grade VALUES('0001','0001',80);
INSERT INTO grade VALUES('0001','0002',91);
// Delete
DELETE FROM stu WHERE Student number ='0004';
// modify
UPDATE stu SET Home address =' Xinjian Road, Binjiang city 96 Number ' WHERE Student number ='0002';5、 Concept of view , The difference between a table and a view ?
Concept : Virtual table , Tables exported from one or more tables
difference :
1) The view is compiled SQL sentence
2) The table has a physical structure , View none
3) Table belongs to internal mode , View belongs to external mode
4) The table is the content , Trying to be a window
5) Deleting and creating views does not affect the table
6、 establish 、 Delete the statement of the view ?
// establish
CREATE VIEW < View name >;
// Delete
DROP VIEW < View name >;7、 The function of view ?
1) Improved reusability , View is like a function .
2) Refactoring the database , It doesn't affect the operation of the program .
3) Improved security performance . It can be applied to different users , Set different views .
4) Make the data clearer . What kind of data do you want , Just create what kind of view .
8、NULL The meaning of , usage ?
meaning : I do not know! 、 non-existent 、 meaningless
usage :
1) assignment , Assign a variable NULL value
2) Judge , Determine whether a variable is NULL
9、 The concept of index , type , effect , Create method ?
Concept : Is a sorted list , Store the index value and the physical address corresponding to this value
type : Aggregation class , Non aggregated classes
effect : Speed up queries , Speed up the connection between tables
Create method :
CREATE UNIQUE INDEX < Index name > ON grade( Student number ); CREATE INDEX < Index name > ON grade( Student number );
边栏推荐
- C语言详解系列——循环语句的练习与巩固,二分查找的讲解
- FTXUI基础笔记(botton按钮组件基础)
- How to use Google Earth client and KML Download
- How to do clear scanning: try scanning tailor scantailor advanced | including the usage of scantailor
- I'm 25 years old, but I still can't do anything. What if I can't find a way out? How about we media?
- 【数据库】期末必知必会-----第一章 数据库概述
- Unity - 如何修改一个 Package 或是如何将 Package Local化
- 高性能与经济性兼备:傲腾 持久内存助力移动云应对严苛内存挑战
- Chapter 0 performance platform godeye source code analysis - Course Introduction
- 小程序畢設作品之微信在線教育視頻點播學習小程序畢業設計(3)後臺功能
猜你喜欢

2022 Yangtze River Delta mathematical modeling: Gearbox Fault Diagnosis

Chapter 6 performance platform godeye source code analysis - Custom expansion module

Container adapter - stack, queue, priority queue

Idea configures SFTP and SSH, which is very convenient to deploy and locate error logs

ASP.NET1==visual studio创建asp.net demo

多元统计分析 主成分分析 - 01

英特尔助力开立医疗推动超声产检智能化

Awesome. It turns vscode into idea. It's a little wow

小程序毕设作品之微信在线教育视频点播学习小程序毕业设计(1)开发概要

寻找数组的中心下标
随机推荐
小程序毕设作品之微信在线教育视频点播学习小程序毕业设计(1)开发概要
How session and cookies work
Wechat Online Education video on Demand Learning of applet Graduation Design (3) Background Function
Redis data migration method 4
【超能云终端创领先机】本地计算云端管理,英特尔助力教育数字化
Use case of TS - Snake Eater
小程序毕设作品之微信在线教育视频点播学习小程序毕业设计(4)开题报告
Realize the dual opening of wechat on the computer (log in to two wechat)
Automake Chinese Manual_ incomplete
Frrouting use
JS array processing [slice implements the deletion, insertion and replacement of arrays]
小程序毕设作品之微信电子书阅读小程序毕业设计(7)中期检查报告
PAC十年:见证HPC从CPU时代走向XPU纪元
Dapr series (I)
【数据库】期末必知必会-----第十二章 数据库恢复
【Notebook系列第七期】OpenVINO预训练模型的的下载和使用方法
Understand │ what is cross domain? How to solve cross domain problems?
[untitled]
【数据库】期末必知必会-----第七章 数据库完整性
小程序毕设作品之微信电子书阅读小程序毕业设计(4)开题报告