This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15188|Reply: 2

[Source] Database exam operation questions and answers

[Copy link]
Posted on 4/28/2015 4:52:13 PM | | |

1. There is an order management database, which includes warehouse table, employee table, purchase order form, and supplier table as follows:
Warehouse table (warehouse number, city, area)
Employee table (warehouse number, employee number, salary)
Purchase order form (employee number, supplier number, purchase order number, order date)
Supplier Table (Supplier Number, Supplier Name, City)
Please use SQL statements to complete the following operations (3 points for each question from 1-12, 4 points for 13 questions, a total of 40 points). :
1. Retrieve all wage values from the employee relationship, and require no duplicate values in the results.
2. Search for employee numbers with salaries of more than 1,230 yuan and their city.
3. Search for the employee number of the warehouse with an area greater than 400 and the city where these employees work.
4. Find out which cities have at least one warehouse with a salary of 1250 yuan
5. Search for information on warehouses where the wages of all employees are more than 1210 yuan.
6. Sort by warehouse number in ascending order, then sort by salary in descending order and output all employee information.
7. Obtain the sum of the wages of warehouse workers in Beijing and Shanghai.
8. Seek the maximum salary value of employees working in the WH2 warehouse.
9. Obtain the average salary of each warehouse with at least two employees.
10. Retrieve all supplier information not in Beijing.
11. List the purchase order information with the highest total amount handled by each employee.
12. Search for information on which warehouses do not have employees.
13. Search for the warehouse number where the salary of the employee is greater than or equal to the salary of any employee in the wh1 warehouse


2. The existing relational database is as follows:
Database Name: Teacher Database
Teacher Table (number char(6), name, gender, ethnicity, job title, ID number)
Course schedule (course number char(6), name)
Class schedule (ID, teacher number, class number, number of class hours)
SQL statement code that implements the following functions in SQL language (5 points per question, 40 points in total):
1. Create the database and table creation code of the above three tables;
   Required use: primary key (teacher table. Number, Curriculum. Course number), foreign key (class schedule. Teacher number, class schedule. Class number), default (ethnicity), non-empty (ethnicity, name), unique (ID number), check (gender, number of class hours), automatic number (ID)
2. Add the following course information to the code of the course schedule
       (1) Course number Course name
        100001 SQL Server database
        100002 Data structures
        100003 VB programming
       (2) Change the course name of the course number 100003: Visual Basic Programming
       (3) Delete the course information with the course number 100003  
3. Write out the code to create [Class Schedule View] (teacher number, name, course number, course name, class hours);
4. Write out the embedded table value function and retrieval code to create [a course teacher];
Search: Names of all teachers for the course 'SQL Server Database';
5. Write out and create [Count Class Hours]: output the maximum number of class hours, the minimum number of class hours, the storage procedure of the average class hours, and the execution code.
6. Write out and create: calculate the total class hours of a teacher's substitute teaching, and return the value to the stored procedure and execution code.
Implementation: Calculate the total class hours of "Teacher Guo".
7. Retrieve the information of all teachers with one or more courses with more than 90 class hours, including numbers and names.
8. Create a rule and bind it to the title column of the teacher table, and stipulate that the value is one of ('Professor', 'Associate Professor', 'Lecturer', 'Teaching Assistant').


3. There is a talent information management database, which has three tables.
    Talent Basic Information Form RCDA (number, name, gender, date of birth, salary status)
    Talent Professional Specialty Table ZYTC (number, major, professional years, professional title, English proficiency)
        Talent Achievement Achievement Table CJDA (Number, Achievement Name, Achievement Category, Achievement Source)
  Please use SQL language to complete the following operations (4 points per question, 40 points in total):
1. Query all information in the RCDA table;
2. Query the number, name, gender, date of birth, and salary status, and arrange them in descending order according to the field values of the number.
3. Query number, name, gender, date of birth, and salary status, and require the search for records of salary status exceeding 5,000 yuan or less than 3,000 yuan, and the query results are arranged in ascending order according to the value of the salary status field.
4. Query the information of all fields in the RCDA table and ask to select the records of all gay men.
5. Check the names and salary status of all records in the RCDA form;
6. Check the name, gender and salary status of all men in the RCDA table, and sort them in descending order of salary status;
7. Check the name and date of birth of employees aged 20-30 in the RCDA form;
8. Find the sum of everyone's wages in the RCDA table, and change the column heading to "Sum of wages";
9. Check the sum of wages of male and female employees in the RCDA table;
10. Check the average salary of all owners in the RCDA table;
  1. use master
  2. --删除数据库
  3. if exists (select * from sysdatabases where name='订货管理')
  4. DROP database 订货管理
  5. GO
  6. --创建数据库
  7. CREATE DATABASE 订货管理
  8. GO
  9. --切换数据库
  10. USE 订货管理
  11. Go
  12. --1/创建仓库表(仓库号,城市,面积)
  13. create table 仓库表
  14. (
  15. 仓库号 char(4) primary key,
  16. 城市 varchar(4) not null,
  17. 面积 int
  18. )
  19. go
  20. --2/创建供应商表(供应商号,供应商名,城市)
  21. create table 供应商表
  22. (
  23. 供应商号 char(2) primary key,
  24. 供应商名 char(2),
  25. 城市 varchar(10)
  26. )
  27. Go
  28. --3/创建职工表(仓库号,职工号,工资)
  29. create table 职工表
  30. (
  31. 仓库号 char(4) not null references 仓库表(仓库号),
  32. 职工号 char(2) primary key,
  33. 工资 int
  34. )
  35. Go
  36. --4/创建订购单表(职工号,供应商号,订购单号,订购日期)
  37. create table 订购单表
  38. (
  39. 职工号 char(2) not null references 职工表(职工号),
  40. 供应商号 char(2) references 供应商表(供应商号),
  41. 订购单号 char(2) primary key,
  42. 订购日期 datetime
  43. )
  44. Go

  45. --1、        从职工关系中检索所有工资值,要求结果中没有重复值。
  46. select 职工号,工资 from 职工表
  47. --2、        检索工资多于1230元的职工号和他们所在的城市。
  48. select 城市,职工号 from 仓库表
  49. inner join 职工表 on 仓库表.仓库号=职工表.仓库号
  50. where 工资>1230
  51. --3、        检索工作在面积大于400的仓库的职工号以及这些职工工作所在的城市。
  52. select 职工号,城市 from 职工表
  53. inner join 仓库表 on 职工表.仓库号=仓库表.仓库号
  54. where 面积>400
  55. --4、        检索出哪些城市至少有一个仓库的职工工资为1250元
  56. select 城市 from 仓库表 where 仓库号 in
  57. (select 仓库号 from 职工表 where 工资=1250)
  58. --5、        检索所有职工的工资都多于1210元的仓库的信息。
  59. select * from 仓库表 where 仓库号 in
  60. (select 仓库号 from 职工表
  61. except  
  62. select 仓库号 from 职工表 where 工资<=1210)
  63. --6、        先按仓库号升序排序,再按工资降序排序并输出全部职工信息。
  64. select * from 职工表 order by 仓库号,工资
  65. --7、        求北京和上海的仓库职工的工资总和。
  66. select sum(工资) from 职工表 where 仓库号 in  
  67. (select 仓库号 from 仓库表 where 城市='北京' or 城市='上海')
  68. --8、        求在wh2仓库工作的职工的最高工资值。
  69. select MAX(工资) from 职工表 where 仓库号='wh2'
  70. --9、        求至少有两个职工的每个仓库的平均工资。
  71. select 仓库号,AVG(工资) as 职工平均工资 from 职工表
  72. group by 仓库号
  73. having COUNT(职工号)>=2
  74. --10、        检索出不在北京的全部供应商信息。
  75. select * from 供应商表 where 城市<>'北京'
  76. --11、        列出每个职工经手的具有最高总金额的订购单信息。

  77. --12、        检索哪些仓库中还没有职工的仓库的信息。
  78. select * from 仓库表 where 仓库号 in
  79. (select 仓库号 from 仓库表
  80. Except
  81. select 仓库号 from 职工表)
  82. --13、        检索有职工的工资大于或等于wh1仓库中任何一名职工工资的仓库号
  83. select distinct 仓库号 from 职工表
  84. where 工资 >= (select min(工资) from 职工表 where 仓库号='wh1')


Copy code

  1. --1、
  2. create database 教师数据库  
  3. go               
  4. use 教师数据库
  5. go

  6. create table 教师表                        
  7. (
  8. 编号 char(6) primary key,
  9. 姓名 nchar(4) not null,  
  10. 性别 nchar(1) check([性别] in ('男', '女')),
  11. 民族 nchar(8) default '汉族' not null,
  12. 职称 nchar(12),
  13. 身份证号 char(18) unique )  
  14. go

  15. create table 课程表                          
  16. (课号 char(6) primary key,
  17. 名称 char(40) not null
  18. )  
  19. go

  20. create table 任课表                        
  21. (
  22. ID int IDENTITY(1, 1),  
  23. 教师编号 char(6) references 教师表(编号),
  24. 课号 char(6) references 课程表(课号),  
  25. 课时数 integer check([课时数] between 0 and 200)
  26. )
  27. go
  28. --2、
  29. insert 课程表 values('100001', 'SQL Server数据库')  
  30. insert 课程表 values('100002', '数据结构')
  31. insert 课程表 values('100003', 'VB程序设计')
  32. update 课程表 set 名称='Visual Basic程序设计' where 课号='100003'  
  33. delete 课程表 where 课号='100003'

  34. --3、   
  35. create view [任课表视图] as  
  36. select 教师编号,姓名,任课表.课号,名称,课时数 from 教师表
  37. inner join 任课表 on 教师表.编号=任课表.教师编号
  38. inner join 课程表 on 课程表.课号=任课表.课号

  39. --4、   
  40. create function [某门课任课教师](@课程名 varchar(15))
  41. returns table as  
  42. return (select 名称,课时数,教师姓名=姓名 from 任课表视图 where 名称=@课程名)
  43. go
  44. select * from [某门课任课教师]('SQL Server数据库')

  45. --5、
  46. create procedure [统计课时数]  
  47. as
  48. select  最大课时数=max(课时数) ,最小课时数=min(课时数),平均课时数=avg(课时数)
  49. from 任课表
  50. go  
  51. execute [统计课时数]
  52. --6、   
  53. create procedure [统计课时]  
  54. @教师名 nchar(16)
  55. as     
  56. declare @总课时 int      
  57. select @总课时=sum(课时数) from 任课表视图   
  58. where 姓名=@教师名  
  59. go  
  60. execute [统计课时] '郭老师'
  61. --7、   
  62. select 编号, 姓名 from 教师表  
  63. where 编号 in (select distinct 教师编号 from 任课表 where 课时数>=90)
  64. 8、   
  65. create rule zhicheng_rule  
  66. as @zhicheng  in ('教授','副教授','讲师', '助教')
  67. go  
  68. sp_bindrule zhicheng_rule, '教师表.职称'
Copy code

  1. use master
  2. --删除数据库
  3. if exists (select * from sysdatabases where name='人才信息管理')
  4. DROP database 人才信息管理
  5. GO
  6. --创建数据库
  7. CREATE DATABASE 人才信息管理
  8. GO
  9. --切换数据库
  10. USE 人才信息管理
  11. Go
  12. --人才基本情况表RCDA(编号,姓名,性别,出生日期,工资现状)
  13. create table RCDA
  14. (
  15. 编号 char(4) primary key,
  16. 姓名 varchar(10) not null,
  17. 性别 varchar(2) not null,
  18. 出生日期 datetime,
  19. 工资现状 int
  20. )
  21. go

  22. --人才专业特长表ZYTC(编号,专业,专业年限,职称,英语水平)
  23. create table ZYTC
  24. (
  25. 编号 char(4) primary key,
  26. 姓名 varchar(10) not null,
  27. 性别 varchar(2) not null,
  28. 出生日期 datetime,
  29. 工资现状 int
  30. )
  31. go
  32. --人才成就成果表CJDA(编号,成果名称,成果类别,成果出处)
  33. create table CJDA
  34. (
  35. 编号 char(4) primary key,
  36. 成果名称 varchar(10) not null,
  37. 成果类别 varchar(10) not null,
  38. 成果出处 varchar(10) not null
  39. )
  40. go

  41. --1.查询RCDA表中的所有信息;
  42. Select * from RCDA
  43. --2. 查询编号、姓名、性别、出生日期、工资现状,并按编号的字段值降序排列。
  44. Select 编号,姓名,性别,出生日期,工资现状 from RCDA
  45. order by 编号 desc
  46. --3.查询编号、姓名、性别、出生日期、工资现状,要求查询出工资现状超过5000,或少于3000元的记录,且查询结果按工资现状字段值升序排列。
  47. Select 编号,姓名,性别,出生日期,工资现状 from RCDA
  48. Where 工资现状>5000 or 工资现状<3000 order by 工资现状
  49. --4.查询RCDA表中所有字段的信息,要求选择所有男同志的记录。
  50. Select * from RCDA where 性别='男'
  51. --5.在RCDA表中查询所有记录的姓名和工资现状的情况;
  52. Select 姓名,工资现状 from RCDA
  53. --6.在RCDA表中查询所有男性的姓名、性别和工资现状的情况,并按工资现状降序排序;
  54. Select 姓名,性别,工资现状 from RCDA order by 工资现状 desc
  55. --7. 在RCDA表中查询年龄在20-30岁间的职工的姓名,出生日期;
  56. select 姓名,出生日期,datediff(yy,出生日期,getdate()) as 年龄 from RCDA
  57. where datediff(yy,出生日期,getdate()) between 20  and 30
  58. --8. 在RCDA表中求所有人的工资总和,并将列标题改为“工资总和”;
  59. Select sum(工资现状)  as 工资总和 from  RCDA
  60. --9. 在RCDA表中查询男职工和女职工的工资总和;
  61. Select 性别,sum(工资现状) as 工资总和 from RCDA group by 性别
  62. --10. 在RCDA表中查询所有人的平均工资;
  63. Select avg(工资现状) from RCDA
Copy code






Previous:A small program written in C# used to determine whether the website is a discuz forum or not, and the source code was shared with everyone
Next:The Beijing Cybersecurity Anti-Fraud Alliance released a report on online fraud crimes
Posted on 4/28/2015 7:12:25 PM |
With this, don't worry about not doing it
Posted on 4/29/2015 4:47:56 PM |
Well, the second senior brother is right, Banzhu Daniel, I don't understand the database at all.....
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com