当前位置:网站首页>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_studentMediumtb_studentsurface 、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
边栏推荐
- Redis Cluster集群,主节点故障,主从切换后ip变化,客户端需要处理不
- eventBus
- Get together to watch (detailed version) eat a few cents a day
- The problem of removing spaces from strings
- The penultimate K nodes in jz22 linked list
- Planning code ROS migration POMDP prediction planning (I)
- The express project changes the jade template to art template
- Log4j knowledge point record
- The interface request takes too long. Jstack observes the lock holding
- Classification of technology selection (2022)
猜你喜欢

tf. keras. layers. MaxPooling? D function
![Introduction to ACM [TSP problem]](/img/9f/4e3592542d989b2fbb6d82f7f2fbd2.png)
Introduction to ACM [TSP problem]

【Hcip】OSPF常用的6种LSA详解

Log cutting - build a remote log collection server

Opencv fills the rectangle with a transparent color

Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl

L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)

Deep q-network (dqn)

tf. keras. layers. Embedding function

tf. keras. layers. Conv? D function
随机推荐
Depth deterministic strategy gradient (ddpg)
[unity3d] rolling barrage effect in live broadcasting room
How to build an integrated industrial Internet plus hazardous safety production management platform?
JZ35 replication of complex linked list
REINFORCE
JZ35 复杂链表的复制
Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet
The shell monitors the depth of the IBM MQ queue and scans it three times in 10s. When the depth value exceeds 5 for more than two times, the queue name and depth value are output.
Shell learning notes -- shell processing of output stream awk
Plug in for vscode
Typescript Learning Guide
JZ22 鏈錶中倒數最後k個結點
L2-006 树的遍历(中后序确定二叉树&层序遍历)
Kubernetes - Introduction to actual combat
Difference between relative path and absolute path (often asked in interview)
tf. keras. layers. Timedistributed function
Chapter VII project communication management of information system project manager summary
What is the difference between varchar and char?
Specific field information of MySQL export table (detailed operation of Navicat client)
Regular object type conversion tool - Common DOM class