資料庫課程設計-NBA球隊資訊管理系統
阿新 • • 發佈:2019-01-01
//匯入資料並創立資料庫 /*==============================================================*/ /* DBMS name: Microsoft SQL Server 2008 */ /* Created on: 2017/12/8 16:20:02 */ /*==============================================================*/ create database nba on (name=nba_data,--資料檔案的邏輯名稱,注意不能與日誌邏輯同名 filename='d:\sql_data\nba_data.mdf' ,--物理名稱,注意路徑必須存在 size=10,--資料初始長度為M maxsize=50,--最大長度為M filegrowth=5%)--資料檔案每次增長% log on ( name=nba_log, filename='d:\sql_data\nba_log.ldf ' , size=2 , maxsize=5 , filegrowth=1) go use NBA go if exists (select 1 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F') where r.fkeyid = object_id('coach') and o.name = 'FK_COACH_RELATIONS_COACH') alter table coach drop constraint FK_COACH_RELATIONS_COACH go if exists (select 1 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F') where r.fkeyid = object_id('coach') and o.name = 'FK_COACH_TEACH_TEAM') alter table coach drop constraint FK_COACH_TEACH_TEAM go if exists (select 1 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F') where r.fkeyid = object_id('player') and o.name = 'FK_PLAYER_BELONGS T_TEAM') alter table player drop constraint "FK_PLAYER_BELONGS T_TEAM" go if exists (select 1 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F') where r.fkeyid = object_id('player') and o.name = 'FK_PLAYER_TRAINS_COACH') alter table player drop constraint FK_PLAYER_TRAINS_COACH go if exists (select 1 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F') where r.fkeyid = object_id('team') and o.name = 'FK_TEAM_TEACH2_COACH') alter table team drop constraint FK_TEAM_TEACH2_COACH go if exists (select 1 from sysindexes where id = object_id('coach') and name = 'teach_FK' and indid > 0 and indid < 255) drop index coach.teach_FK go if exists (select 1 from sysindexes where id = object_id('coach') and name = 'Relationship_3_FK' and indid > 0 and indid < 255) drop index coach.Relationship_3_FK go if exists (select 1 from sysobjects where id = object_id('coach') and type = 'U') drop table coach go if exists (select 1 from sysindexes where id = object_id('player') and name = 'belongs to_FK' and indid > 0 and indid < 255) drop index player."belongs to_FK" go if exists (select 1 from sysindexes where id = object_id('player') and name = 'trains_FK' and indid > 0 and indid < 255) drop index player.trains_FK go if exists (select 1 from sysobjects where id = object_id('player') and type = 'U') drop table player go if exists (select 1 from sysindexes where id = object_id('team') and name = 'teach2_FK' and indid > 0 and indid < 255) drop index team.teach2_FK go if exists (select 1 from sysobjects where id = object_id('team') and type = 'U') drop table team go /*==============================================================*/ /* Table: coach */ /*==============================================================*/ create table coach ( cname varchar(256) not null, tname varchar(256) null, coa_cname varchar(256) null, cscore float(10) null, constraint PK_COACH primary key nonclustered (cname) ) go /*==============================================================*/ /* Index: Relationship_3_FK */ /*==============================================================*/ create index Relationship_3_FK on coach ( coa_cname ASC ) go /*==============================================================*/ /* Index: teach_FK */ /*==============================================================*/ create index teach_FK on coach ( tname ASC ) go /*==============================================================*/ /* Table: player */ /*==============================================================*/ create table player ( appearnum float(10) null, rebonds float(10) null, assists float(10) null, pscore float null, pname varchar(256) not null, cname varchar(256) null, tname varchar(256) null, constraint PK_PLAYER primary key nonclustered (pname) ) go /*==============================================================*/ /* Index: trains_FK */ /*==============================================================*/ create index trains_FK on player ( cname ASC ) go /*==============================================================*/ /* Index: "belongs to_FK" */ /*==============================================================*/ create index "belongs to_FK" on player ( tname ASC ) go /*==============================================================*/ /* Table: team */ /*==============================================================*/ create table team ( twin float(10) null, lose float(10) null, cname varchar(256) not null, cname2 varchar(256) null, constraint PK_TEAM primary key nonclustered (cname) ) go /*==============================================================*/ /* Index: teach2_FK */ /*==============================================================*/ create index teach2_FK on team ( cname2 ASC ) go alter table coach add constraint FK_COACH_RELATIONS_COACH foreign key (coa_cname) references coach (cname) go alter table coach add constraint FK_COACH_TEACH_TEAM foreign key (tname) references team (cname) go alter table player add constraint "FK_PLAYER_BELONGS T_TEAM" foreign key (tname) references team (cname) go alter table player add constraint FK_PLAYER_TRAINS_COACH foreign key (cname) references coach (cname) go alter table team add constraint FK_TEAM_TEACH2_COACH foreign key (cname2) references coach (cname) go
ER設計圖
由ER圖生成的物理模型圖