《数据库系统原理》实验二.doc_第1页
《数据库系统原理》实验二.doc_第2页
《数据库系统原理》实验二.doc_第3页
《数据库系统原理》实验二.doc_第4页
《数据库系统原理》实验二.doc_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

数据库系统原理实验报告姓名:姜秀连指导教师:康辉学号:55140727实验日期:2016年6月14日一、实验目的1、巩固数据库的基础知识;2、了解结构化查询语言SQL的概念及其特点;3、学习使用SQLServer2000数据库管理系统软件的一些基本操作;4、掌握用SQL创建数据库的两种方法;5、 掌握用SQL创建数据表的方法;6、 掌握数据表的更新的方法;7、 掌握数据表的各种查询方法。2、 实验原理:创建数据库,准备数据,根据题目写sql语句三、基本操作创建数据库,准备数据,根据题目写sql语句四、实验内容及数据记录1、 Find the name, loan number and loan amount of all customers; rename the column name loan_number as loan_id.select customer.customer_name, loan.loan_number ,loan.amount from customer,loan,borrower where customer.customer_name =borrower.customer_name and borrower.loan_number=loan.loan_numberalter table loan change column loan_number loan_id varchar (255) not null2、 Find the names of all customers whose street includes the substring “Main”.select * from customer where customer_street like %Main%3、 Find all customers who have a loan, an account, or both:Select customer.customer_name from customer,depositor,account,borrower,loanWhere depositor.customer_name=customer.customer_name or customer.customer_name=borrower.customer_name group by customer.customer_name4、 Find all customers who have both a loan and an account.Select customer.customer_name from customer,depositor,account,borrower,loanWhere depositor.customer_name=customer.customer_name and customer.customer_name=borrower.customer_name group by customer.customer_name5、 Find all customers who have an account but no loan.Select distinct customer.customer_name from customer,depositor,borrowerWhere depositor.customer_name=customer.customer_nameandcustomer.customer_name not in(Select customer.customer_name from customer,depositor,borrowerWhere customer.customer_name=borrower.customer_name)6、 Find the average account balance at the Perryridge branch.select avg(balance) from account where branch_name=Perryridge7、 Find the number of tuples in the customer relation.select count(customer_name) from customer8、 Find the number of depositors in the bank.Select count(customer.customer_name) from branch,account,depositor,customerWhere branch.branch_name=account.branch_name and account.account_number=depositor.account_number and depositor.customer_name=customer.customer_name9、 Find the number of depositors for each branch.Select branch.branch_name,count(customer.customer_name) from branch,account,depositor,customerWhere branch.branch_name=account.branch_name and account.account_number=depositor.account_number and depositor.customer_name=customer.customer_namegroup by branch.branch_name10、 Find the names of all branches where the average account balance is more than $1,200.selectbranch_name,avg(balance)fromaccountgroupbybranch_namehavingavg(balance)120011、Find all loan number which appear in the loan relation with null values for amount.selectloan_numberfromloanwhereamountisnull12、 Find all customers who have both an account and a loan at the bank.select customer_name from depositorINTERSECTselect customer_name from borrowerSelect distinct c.customer_name from customer c ,depositor d ,borrower b where c.customer_name=d.customer_name and c.customer_name=b.customer_name 13、 Find all customers who have a loan at the bank but do not have an account at the bankSelect distinct customer.customer_name from customer,depositor,borrowerWhere customer.customer_name=borrower.customer_nameandcustomer.customer_name not in(Select customer.customer_name from customer,depositor,borrowerWhere depositor.customer_name=customer.customer_name)14、 Find all customers who have both an account and a loan at the Perryridge branchSelect distinct c.customer_name from customer c,account a,loan l,depositor d,borrower bwhere c.customer_name=d.customer_name and d.account_number=a.account_number and a.branch_name=Perryridgeand c.customer_name=b.customer_name and b.loan_number=l.loan_numberand l.branch_name=Perryridge15、 Find all branches that have greater assets than some branch located in Brooklyn.Select branch.* from branch where assets(select min(assets) from branch where branch_city=Brooklyn)16、 Find the names of all branches that have greater assets than all branches located in Brookly

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论