经济信息管理专业SOL SERVER数据库作业.docx

上传人:b****9 文档编号:28585261 上传时间:2023-07-19 格式:DOCX 页数:19 大小:260.50KB
下载 相关 举报
经济信息管理专业SOL SERVER数据库作业.docx_第1页
第1页 / 共19页
经济信息管理专业SOL SERVER数据库作业.docx_第2页
第2页 / 共19页
经济信息管理专业SOL SERVER数据库作业.docx_第3页
第3页 / 共19页
经济信息管理专业SOL SERVER数据库作业.docx_第4页
第4页 / 共19页
经济信息管理专业SOL SERVER数据库作业.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

经济信息管理专业SOL SERVER数据库作业.docx

《经济信息管理专业SOL SERVER数据库作业.docx》由会员分享,可在线阅读,更多相关《经济信息管理专业SOL SERVER数据库作业.docx(19页珍藏版)》请在冰豆网上搜索。

经济信息管理专业SOL SERVER数据库作业.docx

经济信息管理专业SOLSERVER数据库作业

目录

实验1、SQLServer2000管理工具的使用1

2011年9月131

1、利用企业管理其访问系统自带的pubs数据库1

2、查询分析器的使用2

3.查询pubs数据库publishers表的所有记录3

实验2、创建数据库和表2011年9月203

1创建一个数据库YGGL,包含员工的信息、部门信息以及员工的薪水信息。

3

实验3表数据插入、修改和删除6

2011年9月276

1向表empoyees,deparments,salary中插入记录6

2修改表中salary中某个记录的字段值7

3修改表中salary中所有记录的字段值8

实验4数据库的查询9

2011年10月119

1。

select语句的基本使用9

二.子查询的使用12

三.连接查询的使用14

四.数据汇总15

实验5T-SQL编程2011年10月1818

1自定义数据类型的使用18

2自定义函数的使用18

3重新创建YGGL数据库的employees表19

实验6索引和数据完整性的使用20

2011年10月2520

1对YGGL数据库的employees中departmentid建立索引20

2数据完整性21

实验1、SQLServer2000管理工具的使用

2011年9月13

1、利用企业管理其访问系统自带的pubs数据库

SQLServer2000企业管理器

在pubs数据库中一个表中插入两个记录

2、查询分析器的使用

查询分析器的界面

SQL查询分析器连接对话

3.查询pubs数据库publishers表的所有记录

实验2、创建数据库和表2011年9月20

1创建一个数据库YGGL,包含员工的信息、部门信息以及员工的薪水信息。

1、即Employees:

员工向自然信息表;Departments:

部门信息表;Salary:

员工薪水情况表。

Employees表的结构

Departments表的结构

Salary表的结构

2、使用T-SQL语句创建数据库YGGL,需要启动查询分析器,语句如下:

CREATEDATABASEYGGL

ON

(NAME=’YGGL_Data’,

FILENAME=’e:

\sql\data\MASSQL\Data\YGGL.mdf’,

SIZE=10MB,

MAXSIZE=50MB,

FILEGROWTH=5%)

LOGON

(NAME=’YGGL_Log’,

Filename=’e:

\sql\data\MASSQL\Data\YGGL_Log.ldf’,

SIZE=2MB,

MAXSIZE=5MB,

FILEGROWTH=1MB)

GO

3、运用T-SQL语言创建表Employees

USEYGGL

CREATETABLEEmployees

(EmployeeIDchar(6)NOTNULL,

Namechar(10)NOTNULL,

BirthdaydatetimeNOTNULL,

SexbitNOTNULL,

Addresschar(20)NOTNULL,

Zipchar(6)NULL,

PhoneNumberchar(12)NULL,

EmailAddreechar(20)NULL,

DepartmentIDchar(3)NOTNULL

GO

实验3表数据插入、修改和删除

2011年9月27

1向表empoyees,deparments,salary中插入记录

useyggl

insertintoemployees

values('011112','罗林','1973-5-3',1,'解放路100号',210002,4055663,NULL,5)

go

insertintodeparment

values('2',’人力资源部'NULL)

go

insertintosalary

values('011112',1200.09,50)

go

2修改表中salary中某个记录的字段值

useyggl

updatesalary

setincome=2890

whereemployeeid='011112'

go

3修改表中salary中所有记录的字段值

useyggl

updatesalary

setincome=income+100

go

 

实验4数据库的查询

2011年10月11

1。

select语句的基本使用

查询employees表中所有记录

useyggl

select*

fromemployees

go

电话查询employees中每个雇员的地址和电话

useyggl

selectaddress,phonenumber

fromemployees

go

查询employees中employeeid000001的雇员的地址和电话

useyggl

selectaddressas地址,phonenumberas电话

fromemployees

wheresex=0

go

计算employees中每个雇员的实际收入

useyggl

selectemployeeid,实际收入=income-outcome

fromsalary

go

.找出所有姓王的雇员的部门号

useyggl

selectdepartmentid

fromemployees

wherenamelike'王%'

go

.找出所有收入在2000-3000之间的雇员号码

selectemployeeid

fromsalary

whereincomebetween2000and3000

go

 

二.子查询的使用

.查找在财务部工作的雇员情况

useyggl

select*

fromemployees

wheredepartmentid=

(selectdepartmentid

fromdepartments

wheredepartmentname='财务部')

查找财务部年龄不低于研发部雇员年龄的雇员的姓名

useyggl

selectname

fromemployees

wheredepartmentidin

(selectdepartmentid

fromdepartments

wheredepartmentname='财务部')

and

birthday!

>all(selectbirthday

fromemloyees

wheredeparmentidin

(selectdepartmentid

fromdepartments

wheredepatrmentname='研发部'))

go

查找所有比财务部的雇员收入都高的雇员的姓名

useyggl

selectname

fromemployees

whereemployeeidin

(selectemployeeid

fromsalary

whereincome>

all(selectincome

fromsalary

whereemployeeidin

(selectemployeeid

fromemployees

wheredepartmentid=

(selectdepartmentid

fromdepartments

wheredepartmentname='财务部'))))

go

三.连接查询的使用

1.查每个雇员的情况及薪水情况

useyggl

selectemployees.*,salary.*

fromemployees,salary

whereemployees.employeeid=salary.employeeid

go

.查找财务部收入在2200以上的雇员姓名及薪水情况

useyggl

Selectname,income,outcome

Fromemployees,salary,departments

Whereemployees.employeeid=salary.employeeidandemployees.departmentid=departments.departmentidand

Departmentname=’财务部’andincome>2000

四.数据汇总

1.财务部雇员的平均收入

Useyggl

Selectavg(income)as‘财务部平均收入’

Fromsalary

Whereemployeeidin

(selectemployeeid

Fromemployees

Wheredepartmentid=

(selectdepartmentid

Fromdepartments

Wheredepartmentname=’财务部’))

Go

.财务部雇员的总人数

Useyggl

Selectcount(employeeid)

Fromemployees

Wheredepartmentid=

(selectdepartmentid

Fromdepartments

Wheredepartmentname=’财务部’)

Go

五.GROUPBY.ORDERBY字句的使用

1.求各部门的雇员数

Useyggl

Selectcount(employeeid)

Fromemployees

Groupbydepartmentid

Go

2.将雇员的情况按收入由低到高排列

Useyggl

Selectemployees.*,salary.*

Fromemployees,salary

Whereemployees.employeeid=salary.employeeid

Orderbyincome

Go

实验5T-SQL编程2011年10月18

1自定义数据类型的使用

Useyggl

Execsp_addtype‘id_type’

‘char(6)’,’notnull’

go

2自定义函数的使用

1.createfunctioncheck_id

(@departmentidchar(3))

Returnsintegeras

Begin

Declare@numint

Ifexists(selectdepartmentfromdepartments

Where@departmentid=departmentid)

Select@num=0

Else

Select@num=-1

Return@num

End

Go

3重新创建YGGL数据库的employees表

Useyggl

Ifexists(selectnamefromsysobjects

Wheretype=’u’andname=’employees’)

Droptableemployees

Createtableemployees

(employeeidid_type,

Namechar(10)notnull,

Birthdaydatetimenotnull

Sexbitnotnull,

Addresschar(20)notnull,

Zipchar(6)null,

Phonenumberchar(12)null,

Emailaddreechar(20)null,

Departmentidchar(3)notnull

Go

 

实验6索引和数据完整性的使用

2011年10月25

1对YGGL数据库的employees中departmentid建立索引

Useyggl

Ifexists(selectnamefromsyssindexes

Wherename=’depart_ind’)

Droupindexemployees.depart_ind

Go

Useyggl

Createindexdepart_ind

Onemployees(departmentid)

1.usexscj

ifexists(selectnamefromsysindexeswherename=’kc_id_ind’)

dropindexKC.kc_id_ind

go

createuniqueclusteredindexkc_id_indonKC(课程号)

go

2数据完整性

Createtablebook

(book_idchar(6)

Namevarchar(20)notnull,

Hire_datedatetimenotnull

Costcheck(cost>=0andcost<=500)null

Go

Createdefaulttodayasgetdate()

Go

Execsp_bindefault’today’,’book.[hire_date]’

Altertablebook

AddconstraintBOOK_PK

PRIMARYKEYCLUSTERED(book_id)

Go

 

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 经济市场

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

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