end-of-term review sample paper

end-of-term review sample paper

multiple choice

  1. Writing a modification to the database and writing a running record representing the modification to the log file are two different operations, and the order of these two operations should be B A
    . do the former first

    B.The latter do
    C first. Programmers make arrangements in the program

    D. Which one to do first is determined by the system

  2. Database management systems usually provide authorization functions to control the permissions of different users to access data, which is mainly to achieve (D) of the database.
    A Reliability
    B Consistency
    C Integrity
    D Security

  3. The data independence of the database system refers to (B).
    A Changes in certain storage structures will not affect other storage structures
    B Will not affect applications due to changes in system data storage structures and data logic structures
    C will not affect storage structures due to changes in access strategies
    D will not Affecting applications due to data changes

  4. The three elements of the data model are ( A ).
    A Data structure, data operation and integrity constraints
    B Relational model, hierarchical model, network model
    C Entity, attribute and relationship
    D External schema, schema and internal schema

  5. In the three-level schema structure of the database, it is (A) that describes the global logical structure and characteristics of all data in the database.
    A mode
    B internal mode
    C storage mode
    D external mode

  6. The basic characteristics of the database system are (B).
    A data structure; high data independence: large data redundancy, easy to transplant; data is managed and controlled by DBMS
    B data structure; high data independence: small data redundancy, easy to expand; data is uniformly managed and controlled by DBMS
    C data structure; high data independence; large data redundancy, easy to expand; data is managed and controlled by the file system;
    D data unstructured; data independence is high; data redundancy is small, easy to expand; data is unified by the file system management and control

  7. In the relational model, a keyword is ( D ).

    A cannot consist of all attributes

    B consists of an attribute

    C consists of one or more arbitrary attributes

    D can consist of one or more attributes that uniquely identify any tuple in the relational schema

  8. The B of the database refers to the correctness and compatibility of the data.

    A.safety

    B.integrity

    C. concurrency control

    D. recover

  9. The existing data in the Student , SC and Course tables are as follows:

    Student:

    Sno It takes off Sdept Ssex Sage
    1234501 aaa CS male 21
    1234502 bbb CS female 20
    1234503 ccc IS male 22

    Course

    Cno Cname Cpno He believes
    C01 Uuuuu C08 1
    C02 Vvvv C07 2
    C03 Wwww C06 2
    Q10 Xxxx Q15 3
    C11 Yyyy C16 1
    C12 Zzzz C20 4

    SC

    Sno Cno Grade
    1234501 C01 80
    1234501 C02 88
    1234502 C01 90
    1234503 Q10 85
    1234503 C11 91

    If a foreign key is created on the SC table:
    Foreign Key (Sno) References Student (Sno) ON Delete Cascade

    ON Update NO Action,

    Foreign Key (Cno)References Course(Cno)ON Delete Cascade

    ON Update NO Action,

    Then the following operation is incorrect is D

    A.Delete the basic information of a student in the Student table: (student number 1234501, name aaa, department CS, gender male, age 21), then the first row and the second row of course selection records in the SC table will be deleted;

    B.Change the course number C12 in the Course table to C13

    C.Delete the second line of course selection records on the SC table.

    D.Change the course number C01 in the Course table to C15

    The following operation is incorrect is D. Changing the course number C01 in the Course table to C15 will break the foreign key constraint in the SC table, because the Cno recorded in the first row in the SC table is C01, and C01 does not exist in In the Course table, the record associated with the foreign key cannot be updated, which will cause the update to fail.

    All other operations are correct, as detailed below:

    A. Delete a student’s basic information in the Student table: (student number 1234501, name aaa, department CS, gender male, age 21), then the first row and the second row of course selection records in the SC table will be deleted. This is because in the SC table, the student with the student number 1234501 has taken two courses, C01 and C02, and these two courses are associated with the record with the student number 1234501 in the student information table, so they are deleted in the student information table When the record is deleted, the course selection records related to the student in the SC table will also be deleted in cascade.

    B. Change the course number C12 in the Course table to C13. This operation will not affect the records in the SC table, because the course selection information in the SC table is related according to the course number and the student number. Modifying the course number will not affect the Go to the student course selection information in the SC form.

    C. Delete the second row of course selection records on the SC table. This operation is also correct, because the deletion operation of the SC table will not affect other tables.

  10. Transaction isolation means that C

    A.All operations included in the transaction are either done or not done
    B. Once the transaction is committed, the changes to the database are permanent
    C. The operations and data used within a transaction are isolated from other concurrent transactions
    D. A transaction must change the database from one consistent state to another

  11. There are two transactions T1 and T2, and their concurrent operations are shown in the figure. The following evaluation is correct. C

    A.There is no problem with this operation

    B.The operation loses the modification
    C. This operation cannot be read repeatedly

    D. The operation reads "dirty" data
    insert image description here

  12. The main method of database system concurrency control is to use C mechanism.
    A.reject

    B.Change to serial
    C. blockade

    D. without any control

  13. Common techniques for creating redundant data for data recovery A.

    A. Data dump and check-in log files

    B. Data Backup and Encryption Technology

    C. Views and audits

    D. Database mirroring

  14. The following belongs to the database physical design work is B

    A.Convert ER diagram to relational schema

    B.select access path

    C. Create a data flow diagram

    D. Collect and analyze user activity

  15. In database design, the ER diagram is used to describe the information structure but does not involve the representation of information in the computer, which belongs to the B phase of database design.

    A.demand analysis

    B.Concept Design

    C. logic design

    D. physical design

short answer questions

1. Draw an ER diagram and convert it to a proper relational model

Database information of an IT company:

①The department has a department number, department name, and office location;

②Departmental employees have employee numbers, names, and grades, and employees only work in one department;

③Each department has only one department employee as the department manager;

④ Interns have an internship number, name, and age, and only work in one department;

⑤The project has a project number, project name, start date, and end date;

⑥One employee is in charge of each project, and several employees and interns participate;

⑦ An employee is only responsible for one project, can participate in multiple projects, and has working hours in each project;

⑧Each intern can only participate in one project.

(1) Try to draw the ER diagram of this database.

(2) Transform into an appropriate relational model, and give the primary key and external key of the relation.

insert image description here

Department (department number, department name, office location, department manager employee number)

Master Code: Department Number

Outer code: department manager number -> employee (employee number)

Employee (employee number, name, level, department number)

Master code: employee number

Outer code: department number -> department (department number)

Intern (internship number, name, age, department number)

Master Code: Internship Number

Outer code: department number -> department (department number)

Project (project number, project name, start date, end date, responsible employee number)

Master Code: Item Number

Outer code: responsible employee number -> employee (employee number)

Employee project participation relationship (employee number, project number, working time)

Master code: (employee number, project number)

Outer code: employee number -> employee (employee number)

Outer code: ItemNumber -> Item(ItemNumber)

2. Decomposition of standardized mode - teaching relationship (student number, name, age, gender, department, department head, course name, grade)

Known relationship model: teaching (student number, name, age, gender, department, department head, course name, grade), a student belongs to a department, a student can choose several courses, and the elective course has only one grade, one There is only one department chair.

Analyze the relational schema and answer the following questions:

(1) Write out the functional dependency set of the relation, and determine the candidate key of the relation;

(2) Analyze the paradigm level of the relationship model (explain the reason);

(3) If the 3rd normal form is not reached, please perform schema decomposition and normalize to the 3rd normal form.

1) Student ID -> Name, Age, Gender, Department

Student ID, Course Name -> Results

Department -> Department Head

Candidate code (student number, course name)

2) The name and department are partly dependent on the student number, so there is partly dependent on the candidate key, which belongs to 1NF

3) Not belonging to 3NF is decomposed into: R1 (student number, course name, grade) R2 (student number, name, age, gender, department) R3 (department, department head)

3. Relational Algebra - Retrieve the student ID number of the student whose elective course number is C2 or C4

There are three relationships:

S(SNO,SNAME,AGE,SEX)

SC(SNO,CNO,GRADE)

C(CNO,CNAME,TEACHER)

Use relational algebra expressions to express the query statement: Retrieve the student ID of the student whose elective course number is C2 or C4.

πSNO​(σCNO='C2' ∨ CNO='C4'(SC))

4. Relational Algebra - Retrieve the student ID and name of the student who did not study the course number C2

There are three relationships:

S(SNO,SNAME,AGE,SEX)

SC(SNO,CNO,GRADE)

C(CNO,CNAME,TEACHER)

Use relational algebra expression to express the query statement: Retrieve the student number and name of the student who does not study course number C2.

π(SNO, SNAME)(S) - π(SNO, SNAME)(S ⨝ σ(CNO = 'C2')(SC))

SQL questions

1. Table Definition: Create Availability Table

Availability table spj:

column name illustrate type of data constraint
SNO supplier number CHAR(6) master key
PNO Part Number CHAR(6) master key
JNO project number CHAR(6) master key
QTY supply quantity SMALLINT DEFAULT 100, greater than 0
CREATE TABLE SPJ (
  SNO CHAR(6) NOT NULL,
  PNO CHAR(6) NOT NULL,
  JNO CHAR(6) NOT NULL,
  QTY SMALLINT DEFAULT 100 CHECK (QTY > 0),
  PRIMARY KEY (SNO, PNO, JNO)
);

2. Create a 2016 order information view for customers whose city is Shanghai

Create the order information view v_order of the customer whose city is Shanghai in 2016, including the customer number, customer name, the number of orders and the total order amount of the customer in 2016.

The customer table cutomer table structure is

insert image description here

The order table ` order` table structure is

insert image description here

CREATE VIEW v_order
AS
SELECT customer.customer_id,customer_name,count(order_id),sum(total_money)
from customer,`order`
where YEAR(order_date)=2016 and city="上海" and customer.customer_id = `order`.customer_id
GROUP BY customer.customer_id

3. Create a trigger on the student table student, insert student records, and update the number of people in the class table class synchronously

Create a trigger on the student table student, insert student records, and update the corresponding class number in the class table class synchronously.

The table structure is defined as follows:

Class table class:

classno char(7) class number, primary key,

classname char(20) class name

number int Number of classes.

Student table student:

no char(9) student number, primary key;

name char(10) name;

sex enum('male', 'female') gender;

age SMALLINT age;

classno char(7) class number, foreign key (refer to classno of class for value).

delimiter $$
CREATE TRIGGER update_class_number AFTER INSERT ON student
FOR EACH ROW
BEGIN
    UPDATE class SET number = number + 1 WHERE classno = NEW.classno;
END $$

4. Stored procedure: return the total number of students, the number of boys, the number of girls

#Stored procedure tj_rs: According to the name of the department, count the total number of students, the number of boys, and the number of girls in the department.

[Note: Please use lowercase for the SQL table name]

The student database db_student includes three data tables student (student table), course (curriculum table) and sc (selection table). The table structure is as follows:

1. student (student table):

SNO student number CHAR(7)

SNAMENameCHAR(10)

SSEX Gender CHAR(2)

SAGE AGE SMALLINT

Department of SDEPT VARCHAR(20)

2. course (course schedule)

CNO course number CHAR(10)

CNAME course name VARCHAR(20)

CCREDIT credits SMALLINT

SEMSTER SMALLINT

PERIOD hours SMALLINT

3. sc (course selection table)

SNO student number CHAR(7)

CNO course number CHAR(10)

GRADE grade SMALLINT

CREATE PROCEDURE tj_rs (IN deptName VARCHAR(20), OUT total INT, OUT male INT, OUT female INT)
BEGIN
    SELECT COUNT(*) INTO total FROM student WHERE SDEPT = deptName;
    SELECT COUNT(*) INTO male FROM student WHERE SDEPT = deptName AND SSEX = '男';
    SELECT COUNT(*) INTO female FROM student WHERE SDEPT = deptName AND SSEX = '女';
END;

5. Insert book information

Insert the book information into the book table, among which ISBN 7, book title Combinatorics, author Liu Di, price 36.70, quantity 37.

The table structure is as follows:

book (book) table: bno book number, bname book title, author author, price unit price, quantity inventory number

insert image description here

Please use lowercase for the table name.

INSERT INTO book (bno, bname, author, price, quantity)
VALUES (7, '组合数学', '刘迪', 36.70, 37);

6. SQL update: delete - delete all grade records of "Wu Bin"

There are student, course, and sc tables; delete all achievement records of "Wu Bin".

student:
insert image description here

sc:
insert image description here

course:

insert image description here

DELETE FROM sc
WHERE sno IN(SELECT sno FROM student WHERE sname='吴宾');


7. SQL update: Modify the grade of "Introduction to Computer" course of "Wang Dali" to 70

#Modify the score of "Introduction to Computer" course of "Wang Dali" to 70.

The student database db_student includes three data tables student (student table), course (curriculum table) and sc (selection table). The table structure is as follows:

1. student (student table):

SNO student number CHAR(7)

SNAMENameCHAR(10)

SSEX Gender CHAR(2)

SAGE AGE SMALLINT

Department of SDEPT VARCHAR(20)

2. course (course schedule)

CNO course number CHAR(10)

CNAME course name VARCHAR(20)

CCREDIT credits SMALLINT

SEMSTER SMALLINT

PERIOD hours SMALLINT

3. sc (course selection table)

SNO student number CHAR(7)

CNO course number CHAR(10)

GRADE grade SMALLINT

[Note: Please use lowercase for the SQL table name]

UPDATE sc
SET GRADE = 70
WHERE SNO = (
SELECT SNO
FROM student
WHERE SNAME = '王大力'
    
) AND CNO = (
SELECT CNO
FROM course
WHERE CNAME = '计算机导论'
);

8. Query the sales information of products whose product category name is "all-in-one" and whose sales volume is 45 or more at a time

Query the sales information of products whose product category name is "all-in-one machine" and whose sales quantity is 45 or more at a time, and output the order details id, product number, sales quantity and sales amount, and the results are sorted in ascending order by order details id.

The order details table order_detail table structure is
insert image description here

The product table product table structure is

insert image description here

The product category table category table structure is

insert image description here

SELECT order_detail.order_id, order_detail.buy_number, order_detail.total_money
FROM order_detail
INNER JOIN product ON order_detail.product_id = product.product_id
INNER JOIN category ON product.category_id = category.category_id
WHERE category.name = '一体机' AND order_detail.buy_number >= 45;

9. Query the name and phone number of the customer who ordered the No. 4, 7, and 8 products once

Query the name and phone number of the customer who ordered the No. 4, 7, and 8 products once.

The structure of the customer table customer table is

insert image description here

The order table ` order` table structure is

insert image description here

Order details table order_detail table structure is

insert image description here

The product table product table structure is
insert image description here

SELECT customer_name,phone FROM customer
WHERE customer_id in (SELECT customer_id from `order` 
       where not exists(select * from order_detail od WHERE product_id in(4,7,8) 
AND NOT EXISTS(select * FROM order_detail
WHERE order_id=`order`.order_id and od.product_id = product_id)));

10. Count the number of employees at all levels of positions (excluding NULL), and arrange them in descending order of the number.

Count the number of employees in positions at all levels (excluding NULL), and arrange them in descending order of the number. Output position, number of people.

insert image description here

SELECT COUNT(*) as count
FROM employee
WHERE job_title IS NOT NULL
GROUP BY job_title
ORDER BY count DESC;

Guess you like

Origin blog.csdn.net/m0_60496161/article/details/131094577