当前位置:网站首页>Final examination questions of Database Principles

Final examination questions of Database Principles

2022-06-22 04:41:00 University of science and technology Yunju

score

Four 、 Practical questions ( This topic consists of 1 Little topic , common 18 branch )

1、 Suppose that a factory producing parts has several workshops , Each workshop processes several kinds of parts , Each part is processed in a certain workshop ; The attribute of a workshop has a workshop name ( only )、 Telephone ; Part attributes have part numbers 、 Part name ; The parts are made of different raw materials , The raw materials used for different parts can be the same , It could be different ; The attribute of making has the making time ; The properties of materials include material number and supplier . Please draw the corresponding E-R chart , And write the corresponding relationship pattern .

(1)E-R chart ( Mark the contact type )(10 branch )

(2) The transformed relational schema ( It is required to achieve Third normal form , Primary key and Foreign keys You can use A symbol mark or After the relational mode, the text expresses )(8 branch )

Relationship model

5、 ... and 、SQL Practical questions ( This topic consists of 2 Little topic , The first 1 Little topic 27 branch , The first 2 Little topic 5 branch , common 32 branch )

1、 There is an existing one named “HouseSelling” The database of , There are three tables under this database , As required , Write the corresponding SQL sentence .( common 6 A little question , among 1-3 Each question 4 branch ,4-6 Each question 5 branch , common 27 branch )

(1) Listings (houses),“ House number ” Primary key .

(2) Salesman list (salesman),“ Salesman number ” Primary key .

(3) Sales list (sales),“ Salesman number , House number ” Primary key , Both the salesperson number and the house source number are foreign keys .

explain : In the following data sheets “()” Part is field type ,SQL When you write a statement Please write the field name correctly , If the field name is misspelled, points will be deducted .

houses surface

House number

(char(12))

Community name (char(20)

area

(float)

The total price

(decimal(10,2))

floor

(int)

General floor (int)

Completion date (date)

Number of rooms

(int)

100-5-202

Tianhua garden

55.90

1000000.00

2

15

2010.7.1

1

111-10-401

Zhongcheng Pavilion

85.73

1700000.00

4

5

2013.12.2

2

100-2-801

Shiyuan City

110.21

2298900.00

8

12

2015.9.1

3

233-1-302

Philanthropic predestination

79.27

1595000.00

3

6

2018.7.1

2

100-5-302

Tianhua garden

55.90

1050000.00

2

15

2010.7.1

1

111-10-501

Zhongcheng Pavilion

85.73

1760000.00

4

5

2013.12.2

2

100-2-1001

Shiyuan City

110.21

2198900.00

8

12

2015.9.1

3

233-1-602

Philanthropic predestination

79.27

1545000.00

3

6

2018.7.1

2

sales surface

Salesman number

(char(7))

House number

(char(12))

Sales date

(date)

10002

111-10-401

2014-5-3

12010

233-1-302

2018-10-2

12003

233-1-602

2018-9-10

10002

100-5-302

2011-1-2

salesman surface

Salesman number

(char(7))

full name

(char(10)

Gender

(char(2)

Telephone

(char(11))

10002

Sun Hua

male

13502100210

12003

Zhang Guihua

Woman

13502100211

12010

Liu Yuanhang

male

13502100212

15079

Wangxingxin

male

13502100213

  1. Query all in 2015 Information on houses built in and after , Include listing number 、 Community name 、 area 、 The total price 、 Number of rooms .

Select  House number , Community name , area , The total price , Number of rooms from houses Where year( Completion date )>=2015

  1. stay salesman Insert a record in the table , full name : still , male , The number is 20001, The mobile number is 15120136490.

Insert into salesman values (20001, still , male ,15120136490)

  1. The number is “10002” The salesperson changed his mobile phone number for some reason , Please be there. salesman Change its mobile phone number to “18902016688”.

Update salesman set  Telephone =18902016688 where  Salesman number =10002

  1. Delete the salesperson information without sales performance .

Delete from salesman where  Salesman number not in (Select distinct  Salesman number from sales)

  1. Query the information about the houses sold by the female salesperson , Including name, 、 House number 、 community 、 Area and total price .

Select  full name , House number , community , area , The total price from houses h,salesman sm,sales ss

Where h. House number =ss. House number and sm. Salesman number =ss. Salesman number and  Gender = Woman

  1. Count the number of houses in each community , Display the name of the community and the number of houses .

Select  Community name ,count(*) AS Number of houses available from houses group by  Community name

2、 According to the corresponding requirements , Write the corresponding T-SQL sentence , Complete related functions .( common 2 Little topic , please Choose any question   Answer , common 5 branch )

According to the previous question “HouseSelling” Complete the following two questions , Choose any question Can be completed .

  1. Establish a stored procedure to count the historical sales performance of salespeople p_sales_smno( The salesperson number is the input parameter ), Display the salesperson's name 、 House number 、 Sales date 、 Total price information , And call execution ( The query salesperson number is 10002 Historical sales performance ).

stored procedure :

Create proc p_sales_snmo @smno char(7) AS

Select  full name , House number , Sales date , The total price from houses h,salesman sm, sales ss

Where h. House number =ss. House number and sm. Salesman number =ss. Salesman number

And  Salesman number [email protected]

Calls to perform :

execute p_sales_smno 10002

  1. Set up triggers t_house_update, When updating the listing information , The total price should be within 100 Wan to 300 Between ten thousand , otherwise , Tips “ The price is out of range ”, And cancel the relevant operation .

Create trigger t_house_update on houses After Update AS

If not exists(select * from inserted where The total price between 1000000 and 3000000)

Begin

Rooback;

Print  The total price is out of range ;

End

原网站

版权声明
本文为[University of science and technology Yunju]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220434221401.html