数据库系统原理实验报告 联系客服

发布时间 : 星期四 文章数据库系统原理实验报告更新完毕开始阅读17df3f17bc23482fb4daa58da0116c175f0e1e04

.

b、alter table employee add constraint ck_emp_no check(emp_no like 'e[0-9][0-9][0-9][0-9][0-9]'); c、alter table employee add constraint ck_sex check(sex like('男''女')); d、alter table sales add constraint ck_inno check(invoice_no like 'i[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'); 5、alter table sales add constraint un_inno unique(invoice_no);

实验4 简单的单表查询

一、实验目的: 熟练掌握用select语句实现简单的单表查询。掌握select子句、from子句、where子句及order by 子句的用法。 二、实验内容 运行查询文件company.sql,生成上机必要的数据,然后完成以下操作。 1、查找所有经理的姓名、职称、薪水。 2、在销售主表sales中查找销售金额大于等于10000元的订单。 3、在员工表employee中查找薪水在4000至8000元之间的员工。 4、在员工表employee中查找住址为上海、北京、天津这三个城市的员工。 5、在客户表customer中查找住址不在上海、北京、天津这三个城市的客户。 6、在员工表employee中查找姓“王”用姓名最后一个字为“功”的员工。 7、在客户表customer中查找姓“刘”的客户名称、电话。 8、查找出职称为“经理”或“职员”的女工的信息。 9、查找薪水最高的前三条员工记录。 10、查找订单金额最高的前10%的订单记录。 11、查找员工表中所属部门(去掉重复记录)。 12、查找员工表中的所有记录,并按薪水由低到高进行排序。 可编辑文档

.

三、实验结果 1、select emp_name,title,salary from employee where title ='经理'; 2、select * from sales where tot_amt>10000; 3、select * from employee where salary between 4000 and 8000; 4、select * from employee where addr in('上海','北京','天津'); 5、select * from customer where addr not in('上海','北京','天津'); 6、select * from employee where emp_name like '王%五'; 7、select cust_name,tel_no from customer where cust_name like '刘%'; 8、select * from employee where title in ('经理','职员') and sex='女'; 9、select top 3 * from employee order by salary desc; 10、select top 10 percent * from sales order by tot_amt desc; 11、select distinct dept from employee; 12、select * from employee order by salary;

实验5 复杂的单表查询

一、实验目的 熟练掌握select查询语句中的group by 子句、having子句的用法,以及汇总函数的使用。 二、实验内容 1、在员工表employee中统计员工人数。 2、统计各部门员工的员工人数及平均薪水。 3、查询销售业绩超过10000元的员工编号。 4、计算每一产品销售数量总和与平均销售单价。 5、统计各部门不同性别、或各部门、或不同性别或所有员工的平均薪水(在group by 子句中使用cube关键字)。 6、统计各部门不同性别、或各部门或所有员工的平均薪水(在group by 子句中使用rollup关键字)。 7、计算出一共销售了几种产品。 可编辑文档

.

8、显示sale_item表中每种产品的订购金额总和,并且依据销售金额由大到小排列来显示出每一种产品的排行榜。 9、计算每一产品每月的销售金额总和,并将结果按销售(月份,产品编号)排序。 10、查询每位业务员各个月的业绩,并按业务员编号、月份降序排序。 三、实验结果 1、select count(emp_no) 总人数 from employee; 2、select dept,count(emp_no) 员工人数,avg(salary) 平均薪水 from employee group by dept; 3、select sale_id,tot_amt from dbo.sales where tot_amt>10000; 4、select prod_id,count(prod_id) 销售总量,avg(unit_price) 平均单价 from dbo.sale_item group by prod_id; 5、select sex,title,avg(salary) 平均薪水 from dbo.employee group by sex,title with cube; 6、select case when(grouping(sex)=1)then 'all' else isnull(sex,'unknown') end as sex, case when(grouping(title)=1) then 'all' else isnull(title,'unknown') end as title, avg(salary) as 平均薪水 from employee group by sex,title with rollup; 7、select distinct count(prod_id) 种类数 from sale_item; 8、select prod_id,sum(qty * unit_price) 总额 from sale_item group by prod_id order by sum(unit_price) desc; 9、select prod_id,month(order_date),sum(unit_price) from sale_item group by prod_id,month(order_date) order by prod_id,month(order_date) desc; 可编辑文档

.

10、select sale_id,month(order_date), sum(tot_amt) from sales group by sale_id,month(order_date) order by sale_id,month(order_date) desc;

实验6 连接查询

一、实验目的 掌握使用连接的方法从多个表中查询数据。理解内连接、外连接(包括左外连接、右外连接和全外连接)、自身连接的概念和使用。要求学生熟练掌握在from子句和在where子句中指定连接条件的这两种方法。 二、实验内容 1、查找出employee表中部门相同且住址相同的女员工的姓名、性别、职称、薪水、住址。 2、检索product 表和sale_item表中相同产品的产品编号、产品名称、数量、单价。 3、检索product 表和sale_item表中单价高于2400元的相同产品的产品编号、产品名称、数量、单价。 4、查询在每张订单中订购金额超过24000元的客户名及其地址。 5、查找有销售记录的客户编号、名称和订单总额。 6、每位客户订购的每种产品的总数量及平均单价,并按客户号,产品号从小到大排列。 7、查找在1997年中有销售记录的客户编号、名称和订单总额。 8、分别使用左向外连接、右向外连接、完整外部连接检索product 表和sale_item表中单价高于2400元的相同产品的产品编号、产品名称、数量、单价。并分析比较检索的结果。 三、实验结果 1、select a.emp_name,a.sex,a.title,a.salary,a.addr from employee a,employee b where a.dept=b.dept and a.addr=b.addr and a.sex='女'; 2、select product.prod_id,prod_name,qty,unit_price from sale_item,product where sale_item.prod_id=product.prod_id; 可编辑文档