ImageVerifierCode 换一换
格式:DOCX , 页数:32 ,大小:1.27MB ,
资源ID:9840712      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9840712.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(数据查询报告.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

数据查询报告.docx

1、数据查询报告实验1 SQL Server 2005 环境(1) 对象资源管理器的使用 进入“SQL Server Management Studio”。 图1.1了解系统数据库和数据库的对象。 图1.2试试不同数据库对象的操作功能 图1.3(3) 查询分析器的使用use studentsysselect * from tblstudentGo 图1.4(4)了解SQL Server Management Studio 中其他窗口的使用方法。图1.5实验2 创建数据库和表(1)在“对象资源管理器”中创建数据库YGGL。图2.1设定数据库的增长方式 如图2.2图2.2图2.3图2.4图2.5(2)

2、删除YGGL数据库 USE masterGODROP DATABASE YGGL(3)使用T-SQL语句创建数据库YGGLcreate database YGGLon( name=YGGL_data,filename=C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDataYGGL.mdf,size=10MB,maxsize=50MB,filegrowth=5%)log on( name=YGGL_log,filename=C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDataYGGL_log.ldf

3、,size=2MB,maxsize=5MB,filegrowth=1MB)Go(4)使用T-SQL语句创建表use YGGLgo create table employees( employeeID char(6)not null primary key,Name char(10)not null,Education char(4)not null,Birthday datetime not null,Sex bit not null default 1,WorkYear tinyint null,Address varchar(40) null,PhoneNumber char(12) nu

4、ll,DepartmentID char(3) not null)Gouse YGGLgo create table Departments( DepartmentID char(3)not null primary key, DepartmentName char(20)not null, Note varchar(100) null)gouse YGGLcreate table Salary( EmployeeID char(6)not null primary key, InCome float not null, OutCome float not null)go实验3 表数据插入、修

5、改和删除(1)在“对象资源管理器”中初始化数据库YGGL中所有表的数据。图3.1图3.2图3.3(2)使用T-SQL命令插入表数据。删除use YGGLgoinsert into employees values(000001,王林,1956-01-23,True,中山路-1-508,210003,335568,null,2,)插入use YGGLgoinsert into Salary(employeeID,Income,Outcome)values(000001,2100.8,123.09)(4)使用SQL语句修改表数据。使用SQL命令修改表Salary中的某个记录的字段值:update

6、salaryset income=2890where employeeid=000001执行上述语句,将编号为000001的职工收入改为2890将所有职工收入增加100:update salaryset income=income+100;执行完,打开Salary表查看数据的变化。使用SQL命令删除表Employmees中编号为000001的职工信息:delete from employees where employeeid=000001删除所有女性员工信息:delete from employees where sex=0使用TRANCATE TABLE语句删除表中所有行:truncate

7、 table salary执行上述语句,将删除Salary表中的所有行。实验4 数据库的查询和视图(3)SELECT语句的基本使用。 对于实验2给出的数据库表结构,查询每个雇员的所有数据。 新建一个查询,在“查询分析器”窗口中输入如下语句并执行:use YGGLselect *from employeesgo用SELECT语句查询Employees表中每个雇员的地址和电话。新建一个查询,在“查询分析器”窗口中输入如下语句并执行:use YGGLgoselect address,phonenumberfrom employees查询EmployeeID为000001的雇员的地址和电话。use Y

8、GGLgoselect address,phonenumberfrom employeeswhere employeeid=000001go查询Employees表中男雇员的地址和电话,使用as子句将结果中各列的标题分别指定为地址、电话。use YGGLgoselect address as 地址,phonenumber as 电话from employeeswhere sex=1go 查询Employees表中员工姓名和性别,要求Sex值为1时显示“男”,为0时显示为“女”。select name as 姓名,casewhen sex=1 then 男end as 性别from employ

9、ees 计算每个员工的实际收入。use YGGL goselect employeeID,实际收入=income-outcomefrom salary获得员工总数。select count(*)from employees找出所有姓王的雇员的部门号。use YGGL goselect departmentidfrom employeeswhere name like 王_找出所有收入在20003000之间的员工的号码。use YGGL goselect employeeidfrom salarywhere income between 2000 and 3000使用INTO子句,由表Salar

10、y创建“收入在1500以上的员工”表,包括编号和收入。use YGGL goselect employeeID as 编号,income as 收入into 收入在以上的员工from salarywhere income1500(4)子查询的使用。1查找在财务部工作的雇员的情况。use YGGL Goselect * from employees,departments where dbo.employees.departmentID=dbo.departments.departmentID and departmentName=财务部2查找财务部年龄不低于研发部雇员年龄的雇员的姓名。use

11、YGGL goselect namefrom employeeswhere departmentid in( select departmentid from departments where departmentname=财务部)andbirthday !all( select birthday from employees where departmentid in( select departmentid from departments where departmentname=研发部) 3查找比所有财务部的雇员收入都高的雇员的姓名。use YGGL goselect namefro

12、m employeeswhere departmentid in( select departmentid from salary where incomeall( select income from salary where departmentid in( select employeeid from employees where departmentid=( select departmentid from departments where departmentname=财务部)(3)连接查询的使用。1查询每个雇员的情况及其薪水的情况。use YGGL goselect emplo

13、yees.*,salary.*from employees,salarywhere employees.employeeid=salary.employeeid2使用内连接的方法查询名字为“王林”的员工所在的部门。use YGGL goselect departmentnamefrom departments join employeeson departments.departmentid=employees.departmentidwhere employees.name=王林3查找财务部收入在2000以上的雇员姓名及其薪水详情。use YGGL goselect name,income,

14、outcomefrom departments ,salary, employeeswhere employees.employeeid=salary.employeeidand employees.departmentid=departments.departmentidand departmentname=财务部and income2000(5)聚合函数的使用1求财务部雇员的平均收入。use YGGL goselect avg(income)as财务部平均收入from salarywhere employeeid in( select employeeid from employees w

15、here departmentid=( select departmentid from departments where departmentname=财务部 )2求财务部雇员的平均实际收入。use YGGL goselect avg(income-outcome)as财务部雇员平均实际收入from salarywhere employeeid in( select employeeid from employees where departmentid=( select departmentid from departments where departmentname=财务部 )3求财

16、务部雇员的总人数。use YGGL goselect count(employeeid)from employeeswhere departmentid=( select departmentid from departments where departmentname=财务部) (6)GROUP BY 、ORDER BY 子句的使用。1查找Employees表中男性和女性的人数。use YGGL goselect sex,count(sex)from employeesgroup by sex;2查找员工数超过2人的部门名称和员工数量。use YGGL goselect employees

17、.departmentid,count(*)as 人数from employees,departmentswhere employees.departmentid=departments.departmentidgroup by employees.departmentidhaving count(*)23将雇员的情况按收入由高到低排列。use YGGL goselect employees.*,salary.*from employees,salarywhere employees.employeeid=salary.employeeidOrder by income 实验4.2 视图的使用

18、实验内容(1)创建视图1创建YGGL数据库上的视图DS_VIEW,视图包含Departments表的全部列。create view DS_VIEWas select* from departments2创建YGGL数据库上的视图Employees_view,视图包含员工号码、姓名和实际收入三列。create view Employees_view(Employeeid,name,realincome)as select employees.employeeid,name,income-outcomefrom employees,salarywhere employees.employeeid=

19、salary.employeeid(2)查询视图。1从视图DS_VIEW中查询出部门号为3的部门名称。select departmentnamefrom ds_viewwhere departmentid=32从视图Employees_view查询出姓名为“王林”的员工的实际收入。select realincomefrom employees_viewwhere name=王林(3)更新视图。1向视图DS_VIEW中插入一行数据:“6,广告部,广告业务”。insert into ds_view values(6,广告部,广告业务) 2修改视图DSVIEW,将部门号为5的部门名称修改为“生产车间”。update ds_view set departmentname=生产车间where departmentid=53修改视图Employees_view中员工号为“000001”的员工的姓名为“王浩”update employees_view set name=王浩where employeeid=0000014删除视图DS_VIEW中部门号为“1”的一行数据。delete from ds_viewwhere departmentid=1(4)删除视图DS_VIEW。drop view ds_view

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1