当前位置:网站首页>Basic SQL (VIII) data update operation practice
Basic SQL (VIII) data update operation practice
2022-04-23 02:58:00 【Siege lion Jason】
Experimental content
According to the database
db_student
Mediumtb_student
surface 、tb_score
、tb_course
, Complete the following UPDATE statement
Table structure
- tb_student(sno,sn,dept,sex,birthday,polity)
- tb_score(sno,cno,score)
- tb_cource(cno,cn,ct,th)
Task solution
Task a
Insert a record into the student form , The student number is 00000000, The name is XXX, The gender is X The record of .
INSERT INTO tb_student(sno,sn,sex)
VALUES('00000000','XXX','X')
Task 2
Insert a record into the student's , The values of each field are :00000000,name,sex,department,XXXX-XX-XX,polity.
INSERT INTO tb_student(sno,sn,sex,dept,birthday,polity)
VALUES('00000000','name','sex','department','XXXX-XX-XX','polity')
Task three
Add a new course to the curriculum , The information is :(‘C8’,‘ New computer technology ’,‘XXX’).
ALTER TABLE tb_course
ADD na varchar(10) null
INSERT INTO tb_course(cno,cn,na)
VALUES('c8',' New computer technology ','XXX')
Task 4
In the elective relationship table SC Add all student pairs to ’C8’ Elective relationship record of the course , The result is tentatively set as 60, Please complete this batch addition task with one command .
INSERT INTO tb_score(sno,cno,score)
SELECT sno,'c8',60 -- cno/score Set value
from tb_student
Task five
Form all the data of girls into a new table , Table, student_girl.
select *
INTO student_girl
FROM tb_student WHERE sex=' Woman '
Task six
Name the students in the form as XX classmate , Change gender to female , The date of birth is 1998-1-1.
UPDATE tb_student
SET sex=' Woman ',birthday='1998-1-1'
WHERE sn='XX'
Task seven
take tb_score In the table c04 The course is equivalent to 60% And plus 40 branch .
UPDATE tb_score
SET score=score*0.6+40
WHERE cno='c04'
Task eight
Increase the scores of students taking data structure courses 15 branch .
UPDATE tb_score
SET score=score+15
WHERE cno=(SELECT cno
FROM tb_course
WHERE cn=' data structure ')
Task nine
Select “ New computer technology ” The grades of male students in the course are temporarily initialized and reset to 0.
UPDATE tb_score
SET score=0
WHERE sno IN (SELECT sno
FROM tb_student
WHERE sex=' male ')
AND cno=(SELECT cno -- Two parallel sub queries
FROM tb_course
WHERE cn=' New computer technology ')
Task ten
Delete all students surnamed Zhang in the student table .
DELETE FROM tb_student
WHERE LEFT JOIN(sn,1)=' Zhang ' -- or WHERE sn LIKE ' Zhang %'
Task 11
Delete student All the information of the failed students in the table .
DELETE FROM tb_student
WHERE sno=(SELECT DISTINCT sno
FROM tb_score
WHERE score<60)
Task 12
XXX Delete all students' information and course selection .
-- If the deletion order is reversed, you will not be able to find XXX Student student id
-- 1. Delete the grade sheet XXX Grade information
DELETE FROM tb_score
WHERE sno=(SELECT sno
FROM tb_student
WHERE sn='XXX')
-- 2. Delete XXX Student information
DELETE FROM tb_student
WHERE sn='XXX'
Task 13
Delete all student information in the student table ( The two methods ).
-- method1
DELETE FROM tb_student
-- method2
TRUNCATE TABLE tb_student
Write the information in the modification table SQL
When the sentence is , follow SET
、UPDATE
、WHERE
The order of writing
That is, set the value first , Then select the scope , Finally, add restrictions . This way of thinking will be clearer
版权声明
本文为[Siege lion Jason]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220644066074.html
边栏推荐
- 接口请求时间太长,jstack观察锁持有情况
- [if you want to do a good job, you must first use its tools] Guide for downloading and using paper editing and document management (endnote, latex, jabref, overflow) resources
- Sonic cloud real machine tutorial
- What is the difference between varchar and char?
- JDBC JDBC
- Traversée de l'arbre L2 - 006
- Error installing Mongo service 'mongodb server' on win10 failed to start
- Decision tree principle of machine learning
- [hcip] detailed explanation of six LSAS commonly used by OSPF
- Step principle of logical regression in machine learning
猜你喜欢
ele之Table表格的封装
Liunx foundation - zabbix5 0 monitoring system installation and deployment
Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)
Fashion MNIST dataset classification training
C language 171 Number of recent palindromes
Shell script learning notes - regular expressions
Linux redis - redis ha sentinel cluster construction details & redis master-slave deployment
It turns out that PID was born in the struggle between Lao wangtou and Lao sky
AC & A2C & A3C
tf. keras. layers. MaxPooling? D function
随机推荐
windows MySQL8 zip安装
JS learning notes
Shell script learning notes -- shell operation on files sed
工业互联网+危化安全生产综合管理平台怎样建
Typescript Learning Guide
B blocks of the 46th ICPC Asian regional competition (Kunming)
The way to conquer C language
Encapsulate components such as pull-down menu based on ele
《信息系统项目管理师总结》第四章 项目成本管理
Chapter IV project cost management of information system project manager summary
The interface request takes too long. Jstack observes the lock holding
Gavl021, gavl281, AC220V to 5v200ma small volume non isolated chip scheme
Plug in for vscode
JZ22 链表中倒数最后k个结点
First knowledge of C language ~ branch statements
[hcip] detailed explanation of six LSAS commonly used by OSPF
Introduction to ACM [TSP problem]
《信息系統項目管理師總結》第六章 項目人力資源管理
C language 171 Number of recent palindromes
Face longitude: