You are on page 1of 5

create table Stadiums(StadFullName varchar(20) constraint StadPK primary key, StadCity varchar(10) not null, StadStreetNr int not

null, StadDateofFoundation date constraint StadYearCheck Check(StadDateofFoundation>'1700-01-01'), Aprice money default 100, BPrice money default 80, CPrice money default 40, Capacity int ) create table Repairs(RepID int identity(1,1) constraint RepPK primary key clustered, StadFullName varchar(20) not null constraint RepStadFK foreign key references Stadiums ON DELETE Cascade on Update cascade, CompanyName varchar(20), RepBeginDate date, RepEndDate date, Cost money not null, Reason varchar(20), constraint DateCheck CHECK (RepBeginDate<=RepEndDate) ) create table Federations(FedFullName varchar(20) constraint FedPK primary key, FedDateofFoundation date constraint FedYearCheck Check(FedDateofFoundation>'1700-01-01'), FedCity varchar(20), FedStreet varchar(20), FedStreetnr int, FIFAenrollment date not null, FedBudget money) create table Referees(LicenseNumber varchar(6) constraint CheckLicense check(LicenseNumber like '[a-c][0-9][0-9][0-9][0-9][0-9]') constraint RefPK primary key, FullName varchar(20) not null,BirthDate date not null) create table RefFed(LicenseNumber varchar(6) constraint RefFedRFK foreign key references Referees on update cascade on delete cascade, FedName varchar(20) constraint RefFedFFK foreign key references Federations on update cascade on delete cascade, constraint RefFedPK primary key(LicenseNumber,FedName)) create table SportEntities(SEFullName varchar(20) constraint SpoEntPK primary key, SEHomeKit image, SEAwayKit image, SEReserveKit image, FedFullName varchar(20) not null constraint SEFedFK foreign key references Federations on update cascade on delete no action, Category varchar(20) not null, SEStadFullN varchar(20) constraint SEStadFK foreign key references Stadiums on update cascade on delete set default )

create table Trophies(SEFullName varchar(20) constraint TrophFK foreign key references SportEntities on update cascade on delete no action, TrophyName varchar(20) constraint TrophyName check (TrophyName in ('Champions League', 'Europa League', 'Primera Division Championship', 'Copa del Rey', 'World Cup', 'European Cup')), Year int, constraint TrophiesPK primary key (TrophyName, Year)) create table NationalTeams( NatFullName varchar(20) constraint NatPK primary key constraint NATFK foreign key references SportEntities on Delete cascade on update cascade, CountryName varchar(20) not null, AgeGroup char(3) not null constraint AGCHECK check (AgeGroup IN ('U15','U18','U21','SEN')), constraint UniqueNat unique(CountryName,AgeGroup) ) create table Clubs (CluFullName varchar(20) constraint CluPK primary key constraint SEFK foreign key references SportEntities, CluYearOfFounding date, CluLegalForm varchar(20), CluIncome money, CluSpending money, CluNetProfit money, CluLogo image default null, CluTeamPhoto image default null, CluUefaRank int not null constraint RankUnique unique, SeasonsInPD int, WinsInRowRec int, LossesInRowRec int, CityPopulation int ) create table Socios(SocioID int identity(1,1) constraint SocPK primary key, Passport varchar(30) not null constraint UPassSoc unique, Country varchar(20), SocFirstName varchar(20), SocSecondName varchar(20), SocBirthDate date) create table ClubSocio(SocioID int constraint FKSoc foreign key references Socios on update cascade on delete cascade constraint CluSocPK primary key, CluFullName varchar(20) not null constraint FKClu foreign key references Clubs on delete cascade on update cascade, EnrollmentDate date not null, Donation money not null) create table Players(PlayID int identity(1,1) constraint PlayPK primary key, PlayFirstName varchar(20) not null, PlaySecondName varchar(20) not null, PlayCity varchar(20), PlayStreet varchar(20), PlayStNr int, PlayBirthDate date, PlayCountry varchar(20),PlayValue money default $0, PlayNatFullName varchar(20) default null constraint PLayFK foreign key references NationalTeams on update cascade on delete set default, PlayPhoto image default null, PreferredFoot varchar(20), constraint CheckFoot Check (PreferredFoot IN ('right','left','both')) ) create table Injuries(PlayerID int constraint InjFK foreign key references Players on update cascade on delete cascade, InjuryType varchar(20), InjuryDate date, SurgeryDate date, RecoveryDate date, constraint InjPK primary key(PlayerID, InjuryType, InjuryDate), constraint InjuryDateCheck check(InjuryDate<SurgeryDate and SurgeryDate<RecoveryDate) ) create table PlayerClub(PlayerID int constraint PCPlayFK foreign key references Players on update cascade on delete no action,

ClubFullName varchar(20) default null constraint CluFK foreign key references Clubs on update cascade on delete set default, ContractCode varchar(10) constraint PlayCluPK primary key, constraint CodeCheck check(ContractCode like '[a-z][a-z][a-z][a-z][a-z][0-9][0-9][0-9][09][0-9]'), ContractBeginning date,ContractMaturity date,Salary money, constraint ContractDateCheck check (ContractBeginning<ContractMaturity), constraint OneEmp unique(PlayerID, ContractBeginning) ) Create table Matches(MatchId int identity(1,1) constraint matchPK primary key, HomeTeam varchar(20) not null constraint Hometeam foreign key references SportEntities on update no action on delete no action, AwayTeam varchar(20) not null constraint Awayteam foreign key references SportEntities on update no action on delete no action, Stadium varchar(20) not null constraint MatchStadium foreign key references Stadiums on update no action on delete no action, MatchDate date not null, TournamentName varchar(20), MatchTime time, FirstHLength int, SecondHLength int, HomeTeamBallPosession real constraint PercentH check (HomeTeamBallPosession>=0 And HomeTeamBallPosession<=100), AwayTeamBallPosession real constraint PercentA check (AwayTeamBallPosession>=0 And AwayTeamBallPosession<=100), Constraint HTU unique(HomeTeam,MatchDate), Constraint ATU unique(AwayTeam,MatchDate), Constraint TEamCheck check(HomeTeam<>AwayTeam) ) create table Agencies(AgencyFullName varchar(20) constraint AgPK primary key, City varchar(15), Street varchar(20), StreetNr int ) create table PhonesofAgencies(AgencyName varchar(20) constraint APFK foreign key references Agencies on update cascade on delete cascade, Agent varchar(20), Phone int, constraint AgPhoPK primary key(Phone)) create table AgenciesClubs(AgencyName varchar(20) constraint AgCluAFK foreign key references Agencies on update cascade on delete cascade, ClubName varchar(20) constraint AgCluCFK foreign key references Clubs on update cascade on delete cascade, TransactionInvoiceNumber int, TransactionValue money, constraint AgeCluPK primary key(AgencyName, ClubName,TransactionInvoiceNumber, TransactionValue)) create table AgenciesPlayers(PlayerID int constraint APPFK foreign key references Players on update cascade on delete no action, AgencyName varchar(20) constraint APAFK foreign key references Agencies on update cascade on delete no action, ContractBeginning date, ContractMaturity date, Commission real constraint ComCheck check(Commission>=0 and Commission<=1), constraint AgePlayPK primary key(AgencyName, PlayerID, ContractBeginning)) create table RefPerformance(LicenseNumber varchar(6) constraint RefPerRFK foreign key references Referees on update cascade on delete cascade, MatchID int constraint RefPerMFK foreign key references Matches on update cascade on delete no action, Mark int constraint MarkCheck check(Mark>0and Mark<11), constraint RefperPK primary key(LicenseNumber,MatchID))

create table Goals(MatchID int constraint GoalMatchFK foreign key references Matches on update cascade on delete cascade, PlayerID int constraint GoalScorerFK foreign key references Players, EventMinute int ) create table Cards(MatchID int constraint CardMatchFK foreign key references Matches on update cascade on delete cascade, PlayerID int constraint CardGoalScorerFK foreign key references Players, EventMinute int ) create table Assists(MatchID int constraint AssMatchFK foreign key references Matches on update cascade on delete cascade, PlayerID int constraint AssScorerFK foreign key references Players, EventMinute int ) create table Coaches(CoachID int identity(1,1) constraint CoachPK primary key, FullName varchar(20) not null, CoaAddress varchar(40) not null, BirthDate date, Nationality varchar(20) not null) create table Staff(StaffID int identity(1,1) constraint StaffPK primary key, FullName varchar(20) not null, StaAddress varchar(40) not null, BirthDate date, Nationality varchar(20) not null, Department varchar(20) not null) create table SECoaches(SEFullName varchar(20) constraint SECSE foreign key references SportEntities on update cascade on delete cascade, CoachID int constraint SECC foreign key references Coaches on update cascade on delete cascade, ContractBeginning date not null, ContractMaturity date not null, Salary money) create table SEStaff(SEFullName varchar(20) constraint SESSE foreign key references SportEntities on update cascade on delete cascade, CoachID int constraint SESS foreign key references Staff on update cascade on delete cascade, ContractBeginning date not null, ContractMaturity date not null, Salary money) create table Sponsors(RegNum varchar(12) constraint RegNumCheck check(RegNum like'[a-z][a-z][0-9][0-9][0-9][0-9][0-9][0-9][0-9][a-z][a-z][a-z]') constraint SpoPK primary key, Industry varchar(20) not null, LegalForm varchar(20), Name varchar(20) not null ) create table SeSpo(SEFullName varchar(20) constraint SeSpoSEFK foreign key references SportEntities on update cascade on delete cascade, RegNum varchar(12) constraint SeSpoSpoFK foreign key references Sponsors on update cascade on delete cascade, ContractBeginning date, ContractMaturity date, Funds money, ContractCode varchar(10) constraint ConCoCheck check(ContractCode like'[0-9][0-9][0-9][09][0-9][0-9][0-9][a-z][a-z][a-z]') constraint SeSpoPK primary key)

create table TVCorporations(Name varchar(20) constraint TVPK primary key, TVPrimeTimeViewersAverage int, TVProfile varchar(20) constraint ProfCheck check(TVProfile in ('Sport','Neutral','News')), Country varchar(20)) create table SeTV(SEFullName varchar(20) constraint SeTVSEFK foreign key references SportEntities on update cascade on delete cascade, Name varchar(20) constraint SeTVTVFK foreign key references TVCorporations on update cascade on delete cascade, AgreementBeginning date, AgreementMaturity date, Funds money, AgreementCode varchar(10) constraint AgreeCoCheck check(AgreementCode like'[0-9][0-9][09][0-9][0-9][0-9][0-9][a-z][a-z][a-z]') constraint SeTVPK primary key) create table TVTech(TVName varchar(20) constraint TechTVFK foreign key references TVCorporations, Technology varchar(20), constraint TechnologyPK primary key(TVName, Technology))

You might also like