In the first half of 2023, database system engineers' real questions and answer analysis in the afternoon

Question 1 (15 points)

In order to improve efficiency, a new energy vehicle company needs to develop an auto parts procurement system. Please complete the database design of the system.

conceptual structure design

Description of Requirement

(1) Record supplier information, including the supplier's name, address and a telephone number.

(2) Record the part information, including the code, name and price of the part.

(3) Record the model information, including the serial number, name and specification of the model.

(4) Record parts procurement information. A certain part of a model can be purchased from multiple suppliers, a certain part can also be used by multiple models, and a certain supplier can also supply multiple parts, including the purchase quantity and purchase date.

logical structure design

According to the entity relationship diagram completed in the conceptual structure design stage, the following relationship model (incomplete) is obtained:

  1. Supplier (name, address, phone)
  2. Part (code, name, price)
  3. Model (number, name, specification)
  4. purchase(model number, supplier name, (a), (b), date of purchase)

Question 1 (5 points)

Supplement the entity connection diagram in the above figure according to the description (no new entities are added).

Question 2 (3 points)

Supplement the two vacancies (a) and (b) in the logical structure design results, and mark the integrity constraints of primary key and foreign key.

Question 3 (7 points)

The automobile company now adds the following requirements: record the sales of models in stores across the country. The store information includes: store number, address and phone number, and the sales include: sales quantity and sales date. The following modifications are made to the original design to achieve this requirement.

(1) Show the store information and its model sales in the figure, and mark the newly added entities and connections and their important attributes.

(2) Give the newly added relationship schema and mark the integrity constraints of primary key and foreign key.

Question 2 (15 points)

Automobile manufacturers manage spare parts in a unified manner and design a corresponding database, one of which records the usage information of repair parts. Its table structure is as follows:

  1. Repair parts usage list (license plate number, repair time, part code, part name, part supplier, part warehouse code, warehouse address, quantity of repair parts).

Among them, the license plate number and accessory code meet the uniqueness. Assuming that the same vehicle may need multiple repair parts in the same maintenance situation, one kind of spare parts can only be stored in one spare parts warehouse, and one kind of spare parts can only be provided by one spare parts supplier. Repair time is accurate to the second.

Question 1 (7 points)

There is data redundancy in the repair parts usage table given in the question. Please give the specific redundant attributes and explain what abnormalities will occur because of this?

Question 2 (8 points)

Does the spare parts use table satisfy BCNF? If not, please decompose the schema so that the decomposed relational schema satisfies BCNF, and mark the primary key and foreign key.

Question 3 (15 points)

Part of the database relational schema of an educational administration management system is as follows:

  1. Student: STUDENT( Sno , Sname, Ssex, Sage, Sdept), each attribute represents student number, name, gender, age, department name;
  2. Course: COURSE ( Cno , Cname , Cpno , Ccredit), each attribute represents the course number, course name, course number and credits of the prerequisite course;
  3. Course selection: SC( Sno , Cno , Grade), each attribute represents the student number, course number, and grade respectively.

A description of the relational schema is as follows:

(1) The underlined attribute is the primary key of the table

(2) The value of the course name is unique.

According to the above description, answer the following questions and complete the vacant part of the SQL statement.

Question 1 (3 points)

Please complete the SQL statement for creating the course table COURSE below, which requires the definition of entity integrity constraints, referential integrity constraints, and other integrity constraints.

CREATE TABLE COURSE(

    Cno CHAR(4) PRIMARY KEY,

    Cname CHAR(30) ( a ),

    Cpno CHAR(4) references ( b ), ( c )

    Ccredit INT

);

Question 2 (4 points)

There is a new course with the course number "C036", which is required for all students to take. The basic information of this course has been entered in the curriculum table COURSE, now need to insert the course selection record of this course in the course selection table SC. The SQL statement to realize this function is as follows, please complete it.

( d ) INTO SC(Sno, ( e ))

      VALUES SELECT Sno,( f ) FROM ( g )

Question 3 (4 points)

Query the indirect prerequisite courses (prerequisite courses of the prerequisite courses) of each course, and require the output of the course number and the course number of the indirect prerequisite courses. Output is required even if a course has no prerequisites, but its indirect prerequisites are empty. This function is realized by the following SQL statement, please complete it.

SELECT K1.Cno,( h )

   FROM COURSE K1 ( i ) OUTER JOIN COURSE K2 ( j ) (( k ) );

Question 4 (4 points)

Query the students who have taken all the courses in the course selection table, and ask to output the student number and name. This function is realized by the following SQL statement, please complete it.

SELECT Sno,Sname FROM STUDENT WHERE NOT EXISTS

  TO

   (SELECT * FROM ( l )

      WHERE ( m )

        (SELECT* FROM ( n )

            WHERE ( o ) );

Question 4 (15 points in total)

The partially simplified relationship model of an enterprise's internal information system is as follows:

  1. Employee table: EMPLOYEES(Eid, Ename, Address, Phone, Jid), the attribute meanings are: employee code, employee name, home address, contact number, job level code.
  2. Job level table: JOB_LEVELS (Jid, Jname, Jbase_salary), the attribute meanings are: job level code, job name, and basic salary of the job.
  3. Employee salary table: SALARY(Eid, attendance_wage, merit_pay, overtime_wage, salary, tax, year, month), the meanings of the attributes are: employee code, attendance salary, performance salary, overtime salary, final salary, tax, year, month.

The business calculates employees' wages on the 25th of every month. Firstly, based on the data in the attendance system and performance system, the employee’s attendance, performance and overtime wages are calculated, and stored in the employee’s payroll; secondly, the final salary is calculated based on the employee’s basic salary for the position, and the record of the employee’s payroll is updated. Finally, the payment of wages is completed according to the employee payroll.

Question 1 (6 points)

The following is the stored procedure program for calculating the final salary of an employee on the 25th of the month, please complete the code in the vacancy.

CREATE PROCEDURE SalaryCalculation( ( a ) empld char(8), IN iYear number(4),

IN iMonth number(2))

DECLARE

   attendance number(14, 2);

   merit number(14, 2);

   overtime number(14, 2);

   base number(14, 2);

   all salary number(14, 2);

BEGIN

  SELECT attendance_wage, merit_pay, overtime_wage INTO ( b )

      FROM SALARY  WHERE Eid=empld FOR UPDATE;

          SELECT Jbase_salary INTO :base

            FROM EMPLOYEES T1,  ( c )

               WHERE T1.Jid=T2.Jid AND T1.Eid= empld;

  all_salary := attendance + merit + overtime + base;

  UPDATE SALARY SET salary = :all_salary

     WHERE ( d ) AND year = iYear AND month = iMonth;

  ( e )

  EXCEPTION WHEN OTHERS THEN ( f )

END

Question 2 (5 points)

In order to prevent illegal modification of employee salary sheets (including internal crimes), the system specifically stipulates the business rules for employee salary sheet modification: the modification of employee salary sheets can only be carried out during the working hours on the 25th of each month. The following is the procedure corresponding to the modification business rules of the employee salary table, please complete the code in the vacancy.

CREATE TRIGGER CheckBusinessRule ( g )

   INSERT OR DELETE OR ( h ) on SALARY FOR EACH ( i )

BEGIN

  IF (TO_CHAR(sysdate, 'DD')<>( j ) OR (to_number(TO_CHAR(sysdate,'HH24')) ( k ) BETWEEN 8 AND 18) THEN

    Raise_Error; // throw an exception

  END IF:

END:

Question 3 (4 points)

The personnel department has the authority to give additional rewards and punishments to employees every month, and the rewards and punishments are also reflected in the final salary of employees. Assume that when the final salary of an employee is calculated in a certain month, the personnel department executes a transaction operation of rewarding the employee with 2,000 yuan at the same time, and the partial scheduling sequence of the corresponding transaction is shown in Table 4-1.

(1) Please explain what kind of concurrency problem exists in this transaction scheduling?

(2) Can the concurrency problem be solved by using 2PL? Will there be a deadlock?

Question 5 (15 points)

The assembly process of a certain equipment needs to go through multiple procedures. Due to the narrow working space, only one person can work in the operation room at the same time. Therefore, after each process needs to complete the delivery of the used accessories, the operator carries the accessories to the operation room for installation. During the installation process, the code of the accessory needs to be scanned to automatically record the installation of the accessory.

Assuming that there are three transactions for handling a certain installation of a certain type of accessories, transaction T1 is responsible for outbound registration, T2 is responsible for installation registration, and T3 is responsible for restocking unused accessories. After all three transactions are executed, the quantity out of T1 should be equal to the sum of the quantity installed in T2 and the quantity restocked in T3. Data item I records the stock quantity of accessories, and data item J records the number of successful installations. In a certain assembly process, 12 accessories were shipped out of the warehouse, and 6 were installed. Assuming that the database system uses the checkpoint mechanism to recover from faults, some log files are shown in Table 5-1 . In the log record content: <Ti, START> means that transaction Ti starts to execute, <Ti, COMMIT> means that transaction Ti commits, <Ti, D, V1, V2> means that transaction Ti modifies the value of data item D from V1 to V2. For example: <T1, D, 22, 3> indicates that transaction T1 modifies the value of the data item from 22 to 3. <Ti, D, V> means to roll back the value of transaction Ti rollback data item D to V. <Ti, abort> indicates the end of transaction Ti rollback. CRASH means that the system disk has an error. Please answer the following questions.

Question 1 (5 points)

Please use 100 words or less to briefly explain the common types of failures in the database system, and explain what type of failures the database shows in the log records in Table 5-1.

Question 2 (4 points)

Please give a list of transactions that need to be redone (Redo) and a list of transactions that need to be undoed (Undo) when the system is restored

Question 3 (6 points)

According to the business logic described in the question stem, please fill in the blank (a) in the log records in Table 5-1; please give the compensation log records for Undo recovery, and fill in the blanks (b) and (c).

In the first half of 2023, database system engineers' real questions and answer analysis in the afternoon

Question 1 (15 points)  Click this link to view the real test analysis video

Question 1 (5 points)

 

 

Question 2 (3 points)

(a) Code of part (b) Purchase quantity

The primary key is a combined primary key (model number, supplier name, part code, purchase date);

Foreign keys: model number, supplier name, part number.

Question 3 (7 points)

(1)

 

 

(2)

Store (store number, address, phone) primary key: store number

Sales (store number, model number, sales quantity, sales date) combined primary key: (store number, model number, sales date), foreign key: store number, model number

Question 2 (15 points)

Question 1 (7 points)

Parts code → (parts name, parts supplier, parts warehouse code)

Spare Parts Warehouse Code → Warehouse Address

Therefore, the part name, part supplier, part warehouse code, and warehouse address are redundant attributes.

There will be insertion exceptions, update exceptions, and deletion exceptions.

Question 2 (8 points)

BCNF is not satisfied.

  1. Repair parts usage table (license plate number, repair time, part code, repair part quantity) primary key: license plate number + repair time + part code, foreign key: part code.
  2. Parts information table (parts code, parts name, parts supplier, parts warehouse code) primary key: parts code, foreign key: parts warehouse code.
  3. Warehouse information table (parts warehouse code, warehouse address) primary key: parts warehouse code

Question 3 (15 points)

Question 1 (3 points)

(a) unique   (b) COURSE  (c) Cno

Question 2 (4 points)

(d) INSERT   (e) Cno   (f) 'C036'   (g) STUDENT

Question 3 (4 points)

(h) K2.Cpno    (i) LEFT   (j) ON   (k) K1.Cpno=K2.Cno

Question 4 (4 points)

(l) COURSE     (m) NOT EXISTS      (n) SC

(o) SC.Sno=STUDENT.Sno AND SC.Cno=COURSE.Cno

Question 4 (15 points in total)

Question 1 (6 points)

(a) IN     (b) :attendance, :merit, :overtime   (c) JOB_LEVELS T2   (d) eid=empId

(e) COMMIT     (f) ROLLBACK    

Question 2 (5 points)

(g) BEFORE    (h) UPDATE   (i) row    (j) ‘25'   (k) NOT

Question 3 (4 points)

(1) The updated latest salary of the reward and punishment affairs of the personnel department may be overwritten by the calculation of the final salary of the calculation of the final salary transaction, that is, there is a lost update.

(2) Yes, deadlock may occur.

Question 5 (15 points)

Question 1 (5 points)

(1) Transaction internal failure; (2) System failure; (3) Media failure.

A system disk error is a media failure.

Parse:

 

 

Question 2 (4 points)

Need to redo (Redo) T2 transaction, need to undo (Undo) T3 transaction.

Question 3 (6 points)

(a)14  (b)<T3,I,8>  (c)<T3,abort>

Guess you like

Origin blog.csdn.net/xiaornshuo/article/details/131832763