您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 工作范文 > 《我的租房网设计与实现》 代码
1《数据库技术与开发》项目实训设计报告项目名称:《我的租房网》姓名:专业:指导教师:完成日期:2内蒙古科技大学信息工程学院计算机系《数据库技术与应用》实验报告姓名学号实验成绩班级实验日期项目号、实验名称实训项目《我的租房网》实验要求1、完成实训项目《我的租房网》并完成实训一到实训4中的上机实践内容2、按照项目实训报告相关要求,提交一份电子版项目实训报告实验内容1、实训一:建立数据库结构(1)创建数据库House使用SSMS向导创建数据库House(2)建立5张数据表--创建客户信息表sys_usercreatetablesys_user(--客户编号,主键标识列UserIdintidentity(1,1)primarykey,--客户姓名,非空UserNamevarchar(50)notnull,--客户密码,至少6个字符UserPwdvarchar(50)constraintck_UserPwdcheck(len(UserPwd)=6))--创建区县信息表hos_districtuseHousegocreatetablehos_district(--区县编号,主键,标识列从1开始,递增值为1DIdintidentity(1,1)primarykey,--区县名称,非空DNamevarchar(50)notnull)--创建街道信息表hos_streetuseHousegocreatetablehos_street3(--街道编号,主键,标识列从1开始,递增值为1StreetIdintidentity(1,1)primarykey,--街道名称,非空SNamevarchar(50)notnull,--区县编号,表hos_district的外键SDIdintconstraintfk_SDIdforeignkey(SDId)referenceshos_district(DId))--创建房屋信息表hos_typeuseHousegocreatetablehos_type(--房屋类型编号,主键,标识列从1开始,递增值为1HTIdintidentity(1,1)primarykey,--房屋类型名称,非空HTNamevarchar(50)notnull)--创建出租房屋信息表hos_houseuseHousegocreatetablehos_house(--出租房屋编号,主键,标识列从1开始,递增值为1HMIDintidentity(1,1)primarykey,--客户编号,非空,外键UserIdintnotnullconstraintfk_UserIdforeignkey(UserId)referencessys_user(UserId),--街道编号,非空,外键StreetIDintnotnullconstraintfk_StreetIDforeignkey(StreetID)referenceshos_street(StreetID),--房屋类型编号,非空,外键HTIdintnotnullconstraintfk_HTIdforeignkey(HTId)referenceshos_type(HTId),--月租金,非空,默认值为0,要求大于等于0Pricedecimal(6,2)notnulldefault(0)constraintck_Pricecheck(Price=0),--标题,非空Topicvarchar(50)notnull,--描述,非空Contentsvarchar(100)notnull,--发布时间,非空,默认值为当前日期,要求不大于当前日期HTimedatetimenotnulldefault(getdate())constraintck_HTimecheck(HTime=getdate()),--备注Copyvarchar(80))4(3)添加外键约束--给客户信息表中的UserName创建非聚集索引createuniquenonclusteredindexIdx_userNameonsys_user(UserName)withfillfactor=10;--给区县信息表中的DName创建非聚集索引createuniquenonclusteredindexIdx_dNameonhos_district(DName)withfillfactor=10;--给街道信息表中的SName创建非聚集索引createuniquenonclusteredindexIdx_sNameonhos_street(SName)withfillfactor=10;--给房屋信息表中的HTName创建非聚集索引createuniquenonclusteredindexIdx_htNameonhos_type(HTName)withfillfactor=10;分析过程:给客户信息表、区县信息表、街道信息表、房屋信息表中添加非聚集索引来提高查询的速度,对经常使用的UserName、DName、SName、HTName进行查询优化2、实训二:添加测试数据(1)主表添加测试数据--向客户信息表sys_user添加多条条测试数据insertintosys_uservalues('王雪丽','100000'),('严德赛','100001'),('王生高','100002'),('崔晓宇','100003'),('卢一帆','100004'),('张英武','100005'),('安鹏','100006'),('胖哥','100007'),('程峰','100008'),('马云','100009'),('王铮','100010'),('刘强东','100011'),('雷舒然','100012'),('成龙','100013'),('武则天','100014'),('焦旭鹏','100015'),('郑利泽','100016'),('罗阳光','100017'),5('邱国龙','100018'),('李小龙','100019')--向区县信息表中添加多条记录insertintohos_districtvalues('洪山区'),('武昌区'),('青山区'),('江汉区'),('硚口区')--向街道信息表中添加多条记录insertintohos_streetvalues('街道口','1'),('卓刀泉','1'),('广埠屯','1'),('石牌岭','1'),('积玉桥','2'),('杨家园','2'),('水果湖','2'),('黄鹤楼','2'),('红卫路','3'),('新沟桥','3'),('冶金街','3'),('厂前街道','3'),('吴家山','4'),('北湖街','4'),('满春街','4'),('新华街','4'),('六角亭','5'),('汉正街','5'),('汉中街','5'),('长风街','5')--向房屋信息表中添加多条记录insertintohos_typevalues('两室一厅'),('两室两厅'),('一室一厅'),('三室两厅'),('四室两厅'),('五室两厅')--建立三张临时表createtable##topic(Topicvarchar(50)notnull,)createtable##contents6(Contentsvarchar(50)notnull,)createtable##copy(Copyvarchar(50)notnull,)--向三张临时表中插入数据insertinto##topicvalues('东方花园')insertinto##topicvalues('金茂东方公寓')insertinto##topicvalues('世贸大酒店')insertinto##topicvalues('民航小区')insertinto##contentsvalues('全新家具电器')insertinto##contentsvalues('简单装修押一付三')insertinto##contentsvalues('精装修,首出租')insertinto##contentsvalues('豪华装修,拎包入住')insertinto##copyvalues('环境优雅,学区房')insertinto##copyvalues('购物方便')insertinto##copyvalues('豪华小区,环境优美')insertinto##copyvalues('交通便利,配套完善')执行结果:如图1、图2、图3、图4、图5图1客户信息表7图2区县信息表图3街道信息表图4房屋信息表8图5三张临时表(2)添加批量数据declare@begindatetime,@enddatetimeset@begin=getdate()--定义局部变量declare@topicvarchar(50)declare@contentsvarchar(50)declare@copyvarchar(50)declare@useridintdeclare@streetidintdeclare@htidintdeclare@pricedecimal(6,2)declare@htimedatetime--向hos_house表中插入10000条数据--使用事物begintransactiondeclare@iintset@i=0while@i100begin--对局部变量进行赋值set@topic=(selecttop1*from##topicorderbynewid())set@contents=(selecttop1*from##contentsorderbynewid())set@copy=(selecttop1*from##copyorderbynewid())selecttop1@userid=useridfromsys_userorderbyNEWID()--租金在-4000之间随机产生set@price=1000+cast(3000*RAND()asint)--发布时间@htime,要求小于当前系统时间,发布时间在当前系统时间一9年内set@htime=cast(dateadd(day,-cast(rand()*datepart(dayofyear,getdate())asint),getdate())asdatetime)set@streetid=(selecttop1StreetIdfromhos_streetorderbynewid())set@htid=(selecttop1HTIdfromhos_typeorderbynewid())--向hos_house中插入数据insertintohos_housevalues(@userid,@streetid,@htid,@price,@topic,@contents,@htime,@copy)set@i=@i+1enddeclare@recordcountintselect@recordcount=(selectcount(*)fromhos_house)if@recordcount100000beginrollbacktransactionprint'插入人数超过上限,插入失败'endelsebegincommittransactionprint'插入成功'endset@end=getdate()PRINTDATEDIFF(millisecond,@begin,@end)/1000.0--单位:s分析过程:定义局部变量,对局部变量进行随机赋值,利用循环语句对hos_house表插入十万条语句,运用事务对插入语句进行优化,缩短插入语句时间。执行结果:如图6图6hos_house表中插入的数据3、实训三:综合查询(1)分页显示查询出租房屋信息10--建立临时表#t,用于存放查询的数据createtable#t(HMIDintprimarykey,UserIdintnotnull,StreetIDintnotnull,
本文标题:《我的租房网设计与实现》 代码
链接地址:https://www.777doc.com/doc-6444194 .html