University of Electronic Science and Technology of China Database and Software Engineering Experiment Report 2

Applicable to network engineering and Internet of Things majors (information and communications)

This experiment is also part of the final exam

Table of contents

Applicable to network engineering and Internet of Things majors (information and communications)

1. Experimental purpose

2. Experimental content

3. Experimental software

4. Experimental procedures and data recording

1. Use SQL Developer to import tables

2. Basic operations of database tables and fields

3. Simple query

4. Advanced query

5. Experimental conclusions and questions

6. Summary and experience

7. Suggestions for improving the experimental process, methods and means


1. Experimental purpose

1. Be familiar with the Oracle environment and learn to use SQL Developer to interact with Oracle;

2. Establish basic database tables and view, modify and delete table structures;

3. Learn to insert, delete, modify and query data in the table.

2. Experimental content

Use the student user in SQL Developer to connect to the Oracle database, import 4 tables: BONUS, DEPT (department table), EMP (employee table) and SALGRADE (salary grade table), perform simple queries and advanced query operations; create a student information table ( INFOS) and score table (SCORES), perform basic operations such as inserting, querying, updating, and deleting database tables and data.

3. Experimental software

Oracle Database, SQL Developer

4. Experimental procedures and data recording

1. Use SQL Developer to import tables

​ (1) Use the student user to connect to the database, and select "Default" for the role.

(2) Paste the SQL script into the worksheet window and click the "Run Script" button. After the import is successful, the data content of the DEPT, EMP and SALGRADE tables queried is as shown in the figure below.

The relevant screenshots are as follows:

figure 1

figure 2

 

image 3

2. Basic operations of database tables and fields

2.1 Create student information table and constraints

After inserting the script, you can get the relationship table.

 

View the "column" and "constraints" contents after the INFOS table is successfully created, as shown in the figure below.

 

Figure 4

Figure 5

 

2.2 Create score table and constraints

Insert script

 

View the "column" and "constraint conditions" contents after the SCORES table is successfully created. The result is as shown in the figure.

 

Figure 6

 

Figure 7

2.3 Insert data

Use the insert command to insert data.

 

View the INFOS table as shown in the figure after successfully inserting data.

Figure 8

 

2.4 Simple query data

Use the SELECT command to query the student information table (INFOS), obtain the name (STUNAME), gender (GENDER), age (AGE) and address (STUADDRESS) information of all students whose gender (GENDER) is "male", and sort them by age.

The query command is:SELECT STUNAME,GENDER,AGE,STUADDRESS FROM INFOS WHERE GENDER=‘Male’ ORDER BY AGE;

The result is as follows:

Figure 9

 

2.5 Update data

Use the UPDATE command to update the following information in the student information table (INFOS) where the student name (STUNAME) is "Ruan Xiaoer":

Class name (CLASSNO) changed to “1002” Residence (STUADDRESS) changed to “Shandong Laihu”

The query command is:UPDATE INFOS SET CLASSNO='1002',STUADDRESS='Shandong Laiwu' WHERE STUNAME='Ruan Xiaoer';

The query results are as shown in the figure

Figure 10

 

2.6 Delete a certain piece of data

Use the DELETE command to delete the student information with the middle school ID (STUID) "s100102" in the student information table (INFOS); then use the SELECT command to query all information in the student information table (INFOS).

删除命令:DELETE FROM INFOS WHERE STUID=‘s100102’;

The result after deletion is shown in the figure:

Figure 11

 

3. Simple query

 Use the three tables that come with Oracle: EMP table (employee table), DEPT table (department table) and SALGRADE table (salary grade table).

​ 1) The year-end bonus for each employee is 2,000 yuan. Please query the EMP table to obtain the names of employees with a basic salary of more than 2,000 yuan, their salaries, and the annual total salary information excluding bonuses.

Related commands:

SELECT ENAME,SAL,12*SAL FROM EMP WHERE SAL>2000;

search result:

 

Figure 12

 2) Please query the EMP table to obtain the names and work information of employees with a salary of more than 2,000 yuan.

4. Advanced query

1) Query the department number of the employee in the EMP table

​Analysis: There may be multiple employees in one department. In this case, you only need to query one result, and there is no need to query multiple pieces of data.

The relevant commands are:

SELECT DISTINCT DEPTNO FROM EMP;

Figure 13

 

2) Query employees whose salary is less than 2,000 and who have not received bonuses

Step 1: Query employees whose salary is less than 2,000.

SELECT ENAME,JOB,SAL,COMM FROM EMP WHERE SAL<2000;

Figure 14

 

Step 2: Query employees whose salary is less than 2,000 and who do not receive bonuses

SELECT ENAME,JOB,SAL,COMM FROM EMP WHERE SAL<2000 AND COMM IS NULL;

Figure 15

 

3) Query employees whose job responsibilities are SALESMAN, PRESIDENT or ANALYST

SELECT ENAME,JOB,SAL FROM EMP

WHERE JOB IN ('SALESMAN', 'PRESIDENT', 'ANALYST');

Figure 16

 

4) Query employees whose salary is between 1000 and 2000

SELECT ENAME,JOB,SAL FROM EMP WHERE SAL BETWEEN 1000 AND 2000;

Figure 17

 

5) Query the name, salary and salary of employees whose names start with J and end with S

SELECT ENAME,JOB,SAL FROM EMP WHERE ENAME LIKE 'J%S';

Figure 18

 

6) Query out the department numbers that do not have employees in the DEPT table

SELECT DEPTNO FROM DEPT MINUS SELECT DEPTNO FROM EMP;

Figure 19

 

7) Query the names, jobs, salaries, and department names of employees whose monthly salary is greater than 2,000 yuan

SELECT e.ENAME,e.JOB,e.SAL,d.DNAME

FROM EMP e,DEPT d  WHERE e.DEPTNO=d.DEPTNO

AND e.SAL>2000;

Figure 20

 

5. Experimental conclusions and questions

Experimental results:

Use SQL language to query, insert, delete and other operations on relational tables in the database, and learnedSQLFlexible use of language, deepened understanding of relational tables, and familiarity with the use of databases.

Thought questions:

  1. Query the name, job, salary, and department name of employees whose job responsibilities are not SALESMAN, PRESIDENT, or ANALYST.

 Order:

​  SELECT ENAME,JOB,SAL,DNAME FROM EMP,DEPT WHERE JOB NOT IN(‘SALESMAN’, ‘PRESIDENT’, ‘ANALYST’) AND EMP.DEPTNO=DEPT.DEPTNO;

The result is as follows:

Figure 21

 

Figure 22

 

2. 换一种方法查询出工资大于 2000 元的员工姓名、工作、工资,及其所在部门名称。

命令:SELECT ENAME,JOB,SAL,DNAME FROM EMP,DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO AND SAL>2000;

查询结果如下:

图23

 

3、查询出每个部门下的员工姓名和工资。请写出 SELECT 命令,并给出查询结果截图。

命令:SELECT ENAME,SAL,DNAME FROM EMP,DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO;

结果如下:

图24

 

4、如果在步骤 2.4 中使用 sys 用户查询学生用户的 INFOS 表,能否查询到学生用户 INFOS 表的添加、删除、修改操作?为什么?如果不同,如何才能让 sys 用户查询到学生用户对 INFOS 表的添加、删除、修改操作?

 不能使用sys用户查询学生用户的INFOS表,因为没有得到dba用户的授权,需要得到dba用户的授权后,才能查询学生用户对INFOS表的添加、删除、修改操作。

六、总结及心得体会

实验中遇到的问题以及解决办法:

  1. 一开始输入脚本进行配置的过程当中,会产生部分错误,然后自己在网上搜索以及在老师的指导之下,解决了这个问题。
  2. 对于实验指导书中没有出现的数据库查询、删除、插入的指令,自己结合课件和网上的一些教程进行学习,最终还是得到了相应的结果。

七、对本实验过程及方法、手段的改进建议

1.在实验中其实相关的脚本也可以适当采取挖空的方式,让学生们进行学习填写。

2.对于插入的关系表,可以适当的增加关系表理解的相关的问题,进行训练。

3.另外,可以适当增加一些SQL语言的练习,以便对学习的知识进行掌握。

Guess you like

Origin blog.csdn.net/weixin_53284122/article/details/129219500