数据库样本.docx
《数据库样本.docx》由会员分享,可在线阅读,更多相关《数据库样本.docx(67页珍藏版)》请在冰豆网上搜索。
数据库样本
--------------------数据库初始化工作-----------------------
setnocounton
setdateformatmdy
go
usemaster
go
ifexists(select*fromsysdatabaseswherename='sports')
dropdatabasesports
go
--------------------数据库的建立-----------------------------
CREATEdatabasesports
ONprimary
(NAME='sports_data',
FILENAME='d:
\database\sports_data.MDF',
SIZE=2,
FILEGROWTH=1,
MAXSIZE=10)
LOGON
(NAME='sports_Log',
FILENAME='d:
\database\sports_Log.LDF',
SIZE=1,
FILEGROWTH=1,
MAXSIZE=5)
GO
------------------表的建立---------------------------------
usesports
ifexists(select*fromsysobjectswherename='match_sort')
droptabledbo.match_sort
go
print'droptablematch_sort'
print'creatematch_sort'
GO
/*赛事类别表*/
createtablematch_sort(
sort_nochar(4)notnull,/*类别编号*/
sort_namechar(10)notnull,/*类别名称*/
primarykey(sort_no)
)
go
----------------------插入数据-----------------------------------
insertintomatch_sortvalues('a001','田赛')
insertintomatch_sortvalues('a002','径赛')
insertintomatch_sortvalues('a003','集体项目')
-----------------------------------------------------------------
ifexists(select*fromsysobjectswherename='match_item')
droptabledbo.match_item
go
print'droptablematch_item'
print'creatematch_item'
GO
/*比赛项目表*/
createtablematch_item(
item_nochar(4)notnullprimarykey,/*项目编号*/
check(item_nolike'I[0-9][0-9][0-9]'),
item_namechar(20)notnull,/*项目名称*/
sort_nochar(4)notnull,/*类别编号*/
qtysmallintnotnull,/*每个项目参赛人(队)数*/
start_timedatetimenotnull,/*比赛开始时间*/
finish_timedatetimenull,/*比赛结束时间*/
foreignkey(sort_no)referencesmatch_sort(sort_no),
constraintck_qtycheck(qty>=8andqty<=50)
)
go
----------------------插入数据------------------------------------------------------------------------
insertintomatch_itemvalues('I001','男子100m预赛','a002',44,'2006-10-2510:
00',null)
insertintomatch_itemvalues('I002','女子100m预赛','a002',44,'2006-10-2510:
30',null)
insertintomatch_itemvalues('I003','女子1500m预决赛','a002',29,'2006-10-2511:
00',null)
insertintomatch_itemvalues('I004','女子跳高','a001',21,'2006-10-2509:
40',null)
insertintomatch_itemvalues('I005','男子跳高','a001',22,'2006-10-2510:
50',null)
insertintomatch_itemvalues('I006','男子铅球','a001',20,'2006-10-2509:
40',null)
insertintomatch_itemvalues('I007','女子铅球','a001',18,'2006-10-2510:
40',null)
insertintomatch_itemvalues('I008','男子100m决赛','a002',8,'2006-10-2514:
30',null)
insertintomatch_itemvalues('I009','女子100m决赛','a002',8,'2006-10-2514:
50',null)
insertintomatch_itemvalues('I010','男子400m预赛','a002',20,'2006-10-2515:
10',null)
insertintomatch_itemvalues('I011','女子400m预赛','a002',17,'2006-10-2516:
00',null)
insertintomatch_itemvalues('I012','男子三级跳远','a001',20,'2006-10-2514:
30',null)
insertintomatch_itemvalues('I013','女子三级跳远','a001',18,'2006-10-2515:
40',null)
insertintomatch_itemvalues('I014','摸石头过河','a003',20,'2006-10-2516:
30',null)
insertintomatch_itemvalues('I015','健身路径','a003',18,'2006-10-2609:
10',null)
insertintomatch_itemvalues('I016','25人负重搬运接力','a003',20,'2006-10-2609:
20',null)
insertintomatch_itemvalues('I017','男子400m决赛','a002',8,'2006-10-2608:
30',null)
insertintomatch_itemvalues('I018','女子400m决赛','a002',8,'2006-10-2609:
00',null)
insertintomatch_itemvalues('I019','男子200m预赛','a002',20,'2006-10-2609:
20',null)
insertintomatch_itemvalues('I020','女子200m预赛','a002',20,'2006-10-2610:
00',null)
insertintomatch_itemvalues('I021','男子200m决赛','a002',8,'2006-10-2614:
20',null)
insertintomatch_itemvalues('I022','女子200m决赛','a002',8,'2006-10-2614:
40',null)
insertintomatch_itemvalues('I023','男子1500m预决赛','a002',16,'2006-10-2615:
10',null)
insertintomatch_itemvalues('I024','女子3000m预决赛','a002',14,'2006-10-2616:
10',null)
insertintomatch_itemvalues('I025','女子跳远','a001',20,'2006-10-2608:
30',null)
insertintomatch_itemvalues('I026','男子跳远','a001',20,'2006-10-2609:
50',null)
insertintomatch_itemvalues('I027','攀越救生墙','a003',18,'2006-10-2615:
00',null)
insertintomatch_itemvalues('I028','10人火车跑','a003',20,'2006-10-2708:
10',null)
insertintomatch_itemvalues('I029','女子800M预决赛','a002',20,'2006-10-2708:
30',null)
insertintomatch_itemvalues('I030','男子800M预决赛','a002',20,'2006-10-2709:
10',null)
insertintomatch_itemvalues('I031','男子4×100m预决赛','a002',20,'2006-10-2709:
50',null)
insertintomatch_itemvalues('I032','女子4×100m预决赛','a002',20,'2006-10-2710:
40',null)
insertintomatch_itemvalues('I033','男子4×400m预决赛','a002',20,'2006-10-2714:
20',null)
insertintomatch_itemvalues('I034','女子4×400m预决赛','a002',20,'2006-10-2715:
20',null)
insertintomatch_itemvalues('I035','男子5000预决赛','a002',18,'2006-10-2716:
30',null)
insertintomatch_itemvalues('I036','20人50M绑腿跑','a003',20,'2006-10-2716:
40',null)
go
----------------------------------------------------------------------------------------------------------------
ifexists(select*fromsysobjectswherename='judge')
droptabledbo.judge
go
print'droptablejudge'
print'createjudge'
GO
/*裁判信息表*/
createtablejudge(
judge_nochar(4)notnullprimarykey,/*裁判编号*/
check(judge_nolike'J[0-9][0-9][0-9]'),
judge_namechar(10)notnull,/*姓名*/
sexchar
(1)notnull,/*性别*/
check(sexin('f','m'))
)
go
----------------------插入数据------------------------------------------------------------------------
insertintojudgevalues('J001','陈一帆','m')
insertintojudgevalues('J002','黎小垣','m')
insertintojudgevalues('J003','宋万达','m')
insertintojudgevalues('J004','李强','m')
insertintojudgevalues('J005','黄萧然','m')
insertintojudgevalues('J006','饶军','m')
insertintojudgevalues('J007','胡云','m')
insertintojudgevalues('J008','梁振','m')
insertintojudgevalues('J009','陈艳','f')
insertintojudgevalues('J010','胡娟','f')
insertintojudgevalues('J011','邓丽彦','f')
insertintojudgevalues('J012','李晓林','f')
insertintojudgevalues('J013','张小燕','f')
insertintojudgevalues('J014','李婷','f')
--------------------------------------------------------------------------------------------------------
ifexists(select*fromsysobjectswherename='duty')
droptabledbo.duty
go
print'droptableduty'
print'createduty'
GO
/*职务表*/
createtableduty(
duty_nochar(4)notnull,/*职务编号*/
duty_namechar(20)notnull,/*职务名称*/
rankingchar(10)null,/*职务级别*/
primarykey(duty_no)
)
go
----------------------插入数据------------------------------------------------------------------------
insertintodutyvalues('D001','计时员','副裁判')
insertintodutyvalues('D002','测量员','副裁判')
insertintodutyvalues('D003','记录员','主裁判')
insertintodutyvalues('D004','其它','副裁判')
--------------------------------------------------------------------------------------------------------
ifexists(select*fromsysobjectswherename='judge_scheme')
droptabledbo.judge_scheme
go
print'droptablejudge_scheme'
print'createjudge_scheme'
GO
/*裁判安排表*/
createtablejudge_scheme(
judge_nochar(4)notnull,/*裁判编号*/
item_nochar(4)notnull,/*项目编号*/
duty_nochar(4)null,/*职务编号*/
isattendchar
(1)null,/*是否到场*/
constraintpk_judge_schemeprimarykeyclustered(judge_no,item_no),
foreignkey(item_no)referencesmatch_item(item_no),
foreignkey(duty_no)referencesduty(duty_no),
check(isattendin('y','n'))
)
go
----------------------插入数据------------------------------------------------------------------------
insertintojudge_schemevalues('J001','I001','D003','y')
insertintojudge_schemevalues('J002','I001','D001','y')
insertintojudge_schemevalues('J003','I001','D001','y')
insertintojudge_schemevalues('J004','I001','D001','y')
insertintojudge_schemevalues('J005','I001','D001','y')
insertintojudge_schemevalues('J009','I001','D001','y')
insertintojudge_schemevalues('J010','I001','D001','y')
insertintojudge_schemevalues('J011','I001','D001','y')
insertintojudge_schemevalues('J012','I001','D001','y')
insertintojudge_schemevalues('J001','I002','D003','y')
insertintojudge_schemevalues('J002','I002','D001','y')
insertintojudge_schemevalues('J003','I002','D001','y')
insertintojudge_schemevalues('J004','I002','D001','y')
insertintojudge_schemevalues('J005','I002','D001','y')
insertintojudge_schemevalues('J009','I002','D001','y')
insertintojudge_schemevalues('J010','I002','D001','y')
insertintojudge_schemevalues('J011','I002','D001','y')
insertintojudge_schemevalues('J012','I002','D001','y')
insertintojudge_schemevalues('J001','I003','D003','y')
insertintojudge_schemevalues('J002','I003','D001','y')
insertintojudge_schemevalues('J003','I003','D001','y')
insertintojudge_schemevalues('J004','I003','D001','y')
insertintojudge_schemevalues('J005','I003','D001','y')
insertintojudge_schemevalues('J009','I003','D001','y')
insertintojudge_schemevalues('J010','I003','D001','y')
insertintojudge_schemevalues('J011','I003','D001','y')
insertintojudge_schemevalues('J012','I003','D001','y')
insertintojudge_schemevalues('J014','I004','D003','y')
insertintojudge_schemevalues('J006','I004','D002','y')
insertintojudge_schemevalues('J014','I005','D003','y')
insertintojudge_schemevalues('J006','I005','D002','y')
insertintojudge_schemevalues('J008','I006','D003','y')
insertintojudge_schemevalues('J013','I006','D002','y')
insertintojudge_schemevalues('J008','I007','D003','y')
insertintojudge_schemevalues('J013','I007','D002','y')
insertintojudge_schemevalues('J001','I008','D003','y')
insertintojudge_schemevalues('J002','I008','D001','y')
insertintojudge_schemevalues('J003','I008','D001','y')
insertintojudge_schemevalues('J004','I008','D001','y')
insertintojudge_schemevalues('J005','I008','D001','y')
insertintojudge_schemevalues('J009','I008','D001','y')
insertintojudge_schemevalues('J010','I008','D001','y')