activefacts-examples 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +22 -0
- data/Rakefile +6 -0
- data/activefacts-examples.gemspec +26 -0
- data/cql/Address.cql +44 -0
- data/cql/Astronomy.cql +35 -0
- data/cql/Blog.cql +54 -0
- data/cql/CinemaBookings.cql +64 -0
- data/cql/CinemaTickets.cql +127 -0
- data/cql/CompanyDirectorEmployee.cql +56 -0
- data/cql/Death.cql +17 -0
- data/cql/Diplomacy.cql +48 -0
- data/cql/Genealogy.cql +98 -0
- data/cql/Health.cql +78 -0
- data/cql/Insurance.cql +320 -0
- data/cql/Marriage.cql +18 -0
- data/cql/Metamodel.cql +567 -0
- data/cql/Monogamy.cql +24 -0
- data/cql/MultiInheritance.cql +22 -0
- data/cql/MultipleSubtyping.cql +30 -0
- data/cql/NonRoleId.cql +14 -0
- data/cql/OddIdentifier.cql +18 -0
- data/cql/OilSupply.cql +53 -0
- data/cql/OneRoleNesting.cql +38 -0
- data/cql/OneToOnes.cql +17 -0
- data/cql/Orienteering.cql +111 -0
- data/cql/PartyModel.cql +38 -0
- data/cql/PersonPlaysGame.cql +18 -0
- data/cql/RedundantDependency.cql +34 -0
- data/cql/SchoolActivities.cql +33 -0
- data/cql/SeparateSubtype.cql +30 -0
- data/cql/ServiceDirector.cql +276 -0
- data/cql/SimplestUnary.cql +12 -0
- data/cql/Supervision.cql +34 -0
- data/cql/VenueSeating.cql +45 -0
- data/cql/WaiterTips.cql +33 -0
- data/cql/Warehousing.cql +101 -0
- data/cql/WindowInRoomInBldg.cql +28 -0
- data/cql/unit.cql +474 -0
- data/diagrams/json/Address.json +41 -0
- data/diagrams/json/Astronomy.json +31 -0
- data/diagrams/json/Blog.json +46 -0
- data/diagrams/json/CinemaBookings.json +53 -0
- data/diagrams/json/CinemaTickets.json +101 -0
- data/diagrams/json/CompanyDirectorEmployee.json +44 -0
- data/diagrams/json/Death.json +20 -0
- data/diagrams/json/Diplomacy.json +34 -0
- data/diagrams/json/Genealogy.json +78 -0
- data/diagrams/json/Insurance.json +259 -0
- data/diagrams/json/Marriage.json +21 -0
- data/diagrams/json/Metamodel.json +318 -0
- data/diagrams/json/Monogamy.json +22 -0
- data/diagrams/json/MultiInheritance.json +25 -0
- data/diagrams/json/MultipleSubtyping.json +22 -0
- data/diagrams/json/OilSupply.json +49 -0
- data/diagrams/json/OneRoleNesting.json +37 -0
- data/diagrams/json/Orienteering.json +94 -0
- data/diagrams/json/PersonPlaysGame.json +22 -0
- data/diagrams/json/RedundantDependency.json +33 -0
- data/diagrams/json/SchoolActivities.json +28 -0
- data/diagrams/json/SeparateSubtype.json +29 -0
- data/diagrams/json/SimplestUnary.json +15 -0
- data/diagrams/json/Supervision.json +27 -0
- data/diagrams/json/VenueSeating.json +40 -0
- data/diagrams/json/WaiterTips.json +29 -0
- data/diagrams/json/Warehousing.json +86 -0
- data/diagrams/json/WindowInRoomInBldg.json +31 -0
- data/images/Address.SQL.png +0 -0
- data/images/Address.png +0 -0
- data/images/Blog.png +0 -0
- data/images/CinemaBookings.png +0 -0
- data/images/CinemaTickets.png +0 -0
- data/images/CompanyDirectorEmployee.png +0 -0
- data/images/Death.png +0 -0
- data/images/Diplomacy.png +0 -0
- data/images/DumpMetamodel.bat +2 -0
- data/images/Genealogy.png +0 -0
- data/images/Insurance/Claim.png +0 -0
- data/images/Insurance/Insurance.png +0 -0
- data/images/Insurance/Person.png +0 -0
- data/images/Insurance/Policy.png +0 -0
- data/images/Insurance/Related.png +0 -0
- data/images/Insurance/VehicleIncident.png +0 -0
- data/images/Marriage.png +0 -0
- data/images/Metamodel/Concepts.png +0 -0
- data/images/Metamodel/Constraints.png +0 -0
- data/images/Metamodel/ContextNote.png +0 -0
- data/images/Metamodel/Diagrams.png +0 -0
- data/images/Metamodel/Language.png +0 -0
- data/images/Metamodel/Legacy.png +0 -0
- data/images/Metamodel/Objects.png +0 -0
- data/images/Metamodel/Populations.png +0 -0
- data/images/Metamodel/Query.png +0 -0
- data/images/Metamodel/Units.png +0 -0
- data/images/Metamodel/ValueConstraints.png +0 -0
- data/images/Metamodel/ValueTypes.png +0 -0
- data/images/MetamodelER.bcp +1 -0
- data/images/MetamodelER.pdf +0 -0
- data/images/MultiInheritance.png +0 -0
- data/images/NorthwindER.png +0 -0
- data/images/OilSupply.png +0 -0
- data/images/Orienteering/Administration.png +0 -0
- data/images/Orienteering/Registration.png +0 -0
- data/images/Orienteering/Scoring.png +0 -0
- data/images/PersonPlaysGame.png +0 -0
- data/images/RedundantDependency.png +0 -0
- data/images/SchoolActivities.png +0 -0
- data/images/SeparateSubtype.png +0 -0
- data/images/SimplestUnary.png +0 -0
- data/images/Supervision.png +0 -0
- data/images/VenueSeating.png +0 -0
- data/images/WaiterTips.png +0 -0
- data/images/Warehousing.png +0 -0
- data/images/WindowInRoomInBldg.png +0 -0
- data/metadata/json/Astronomy.json +175 -0
- data/metadata/json/CinemaBookings.json +354 -0
- data/metadata/json/CinemaTickets.json +768 -0
- data/metadata/json/CompanyDirectorEmployee.json +270 -0
- data/metadata/json/Diplomacy.json +186 -0
- data/metadata/json/Metamodel.json +3214 -0
- data/metadata/json/OilSupply.json +411 -0
- data/metadata/json/SeparateSubtype.json +157 -0
- data/metadata/json/Supervision.json +128 -0
- data/metadata/json/VenueSeating.json +209 -0
- data/orm/.gitignore +11 -0
- data/orm/Address.orm +1268 -0
- data/orm/Astronomy.orm +925 -0
- data/orm/Blog.orm +1711 -0
- data/orm/CinemaBookings.orm +1998 -0
- data/orm/CinemaTickets.orm +5060 -0
- data/orm/CompanyDirectorEmployee.orm +2094 -0
- data/orm/Death.orm +386 -0
- data/orm/Diplomacy.orm +1478 -0
- data/orm/ExampleModels2010.csproj +764 -0
- data/orm/ExampleModels2010.sln +16 -0
- data/orm/Genealogy.orm +3209 -0
- data/orm/Health.orm +2407 -0
- data/orm/Insurance.orm +12727 -0
- data/orm/Marriage.orm +493 -0
- data/orm/Metamodel.orm +20998 -0
- data/orm/Monogamy.orm +328 -0
- data/orm/MultiInheritance.orm +537 -0
- data/orm/MultipleSubtyping.orm +347 -0
- data/orm/OilSupply.orm +2533 -0
- data/orm/OneRoleNesting.orm +1237 -0
- data/orm/Orienteering.orm +3976 -0
- data/orm/PersonPlaysGame.orm +426 -0
- data/orm/RedundantDependency.orm +844 -0
- data/orm/SchoolActivities.orm +961 -0
- data/orm/SeparateSubtype.orm +821 -0
- data/orm/SimplestUnary.orm +172 -0
- data/orm/Supervision.orm +734 -0
- data/orm/VenueSeating.orm +1289 -0
- data/orm/WaiterTips.orm +789 -0
- data/orm/Warehousing.orm +3792 -0
- data/orm/WindowInRoomInBldg.orm +772 -0
- data/rails/models/Astronomy.models +17 -0
- data/rails/models/CinemaBookings.models +123 -0
- data/rails/models/CinemaTickets.models +192 -0
- data/rails/models/Diplomacy.models +126 -0
- data/rails/models/Metamodel.models +894 -0
- data/rails/models/OneRoleNesting.models +18 -0
- data/rails/models/SeparateSubtype.models +49 -0
- data/rails/models/VenueSeating.models +70 -0
- data/rails/schema/Astronomy.schema.rb +25 -0
- data/rails/schema/CinemaBookings.schema.rb +78 -0
- data/rails/schema/CinemaTickets.schema.rb +132 -0
- data/rails/schema/Diplomacy.schema.rb +74 -0
- data/rails/schema/Metamodel.schema.rb +538 -0
- data/rails/schema/OneRoleNesting.rb +20 -0
- data/rails/schema/SeparateSubtype.schema.rb +35 -0
- data/rails/schema/VenueSeating.schema.rb +46 -0
- data/rails/schema/Warehousing.schema.rb +145 -0
- data/ruby/Address.rb +68 -0
- data/ruby/Astronomy.rb +55 -0
- data/ruby/Blog.rb +84 -0
- data/ruby/CinemaBookings.rb +109 -0
- data/ruby/CinemaTickets.rb +218 -0
- data/ruby/CompanyDirectorEmployee.rb +73 -0
- data/ruby/Death.rb +26 -0
- data/ruby/Diplomacy.rb +59 -0
- data/ruby/Genealogy.rb +173 -0
- data/ruby/Insurance.rb +562 -0
- data/ruby/Marriage.rb +21 -0
- data/ruby/Metamodel.rb +621 -0
- data/ruby/Monogamy.rb +27 -0
- data/ruby/MultiInheritance.rb +38 -0
- data/ruby/OilSupply.rb +112 -0
- data/ruby/OneRoleNesting.rb +66 -0
- data/ruby/Orienteering.rb +216 -0
- data/ruby/PersonPlaysGame.rb +31 -0
- data/ruby/RedundantDependency.rb +53 -0
- data/ruby/SchoolActivities.rb +49 -0
- data/ruby/SeparateSubtype.rb +46 -0
- data/ruby/SimplestUnary.rb +10 -0
- data/ruby/Supervision.rb +33 -0
- data/ruby/TwoValues.rb +14 -0
- data/ruby/VenueSeating.rb +64 -0
- data/ruby/WaiterTips.rb +49 -0
- data/ruby/Warehousing.rb +167 -0
- data/ruby/WindowInRoomInBldg.rb +45 -0
- data/sql/server/Address.sql +40 -0
- data/sql/server/Astronomy.sql +36 -0
- data/sql/server/Blog.sql +78 -0
- data/sql/server/CinemaBookings.sql +95 -0
- data/sql/server/CinemaTickets.sql +191 -0
- data/sql/server/CompanyDirectorEmployee.sql +104 -0
- data/sql/server/Death.sql +11 -0
- data/sql/server/Diplomacy.sql +66 -0
- data/sql/server/Genealogy.sql +138 -0
- data/sql/server/Health.sql +169 -0
- data/sql/server/Insurance.sql +484 -0
- data/sql/server/Marriage.sql +30 -0
- data/sql/server/Metamodel.sql +1000 -0
- data/sql/server/Monogamy.sql +20 -0
- data/sql/server/MultiInheritance.sql +27 -0
- data/sql/server/OilSupply.sql +105 -0
- data/sql/server/OneRoleNesting.sql +29 -0
- data/sql/server/Orienteering.sql +186 -0
- data/sql/server/PersonPlaysGame.sql +9 -0
- data/sql/server/RedundantDependency.sql +54 -0
- data/sql/server/SchoolActivities.sql +30 -0
- data/sql/server/SeparateSubtype.sql +33 -0
- data/sql/server/SimplestUnary.sql +9 -0
- data/sql/server/Supervision.sql +30 -0
- data/sql/server/VenueSeating.sql +54 -0
- data/sql/server/WaiterTips.sql +31 -0
- data/sql/server/Warehousing.sql +203 -0
- data/sql/server/WindowInRoomInBldg.sql +13 -0
- data/transform/surrogate/Address.absorption +2 -0
- data/transform/surrogate/Blog.absorption +5 -0
- data/transform/surrogate/CinemaBookings.absorption +7 -0
- data/transform/surrogate/CompanyDirectorEmployee.absorption +7 -0
- data/transform/surrogate/Death.absorption +1 -0
- data/transform/surrogate/Diplomacy-revised.absorption +6 -0
- data/transform/surrogate/Diplomacy.absorption +6 -0
- data/transform/surrogate/Genealogy.absorption +8 -0
- data/transform/surrogate/Insurance.absorption +18 -0
- data/transform/surrogate/Marriage.absorption +2 -0
- data/transform/surrogate/Metamodel.absorption +25 -0
- data/transform/surrogate/Monogamy.absorption +1 -0
- data/transform/surrogate/MultiInheritance.absorption +1 -0
- data/transform/surrogate/MultipleSubtyping.absorption +1 -0
- data/transform/surrogate/OilSupply.absorption +8 -0
- data/transform/surrogate/OneRoleNesting.absorption +1 -0
- data/transform/surrogate/Orienteering.absorption +11 -0
- data/transform/surrogate/PersonPlaysGame.absorption +1 -0
- data/transform/surrogate/RedundantDependency.absorption +3 -0
- data/transform/surrogate/SchoolActivities.absorption +3 -0
- data/transform/surrogate/SeparateSubtype.absorption +3 -0
- data/transform/surrogate/SimplestUnary.absorption +1 -0
- data/transform/surrogate/Supervision.absorption +2 -0
- data/transform/surrogate/WaiterTips.absorption +3 -0
- data/transform/surrogate/Warehousing.absorption +12 -0
- data/transform/surrogate/WindowInRoomInBldg.absorption +1 -0
- data/transform/surrogate/unit.absorption +0 -0
- metadata +374 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
CREATE TABLE Person (
|
2
|
+
-- maybe Person is a Girl and maybe Girl is going out with Boy and Boy is a kind of Person and Person has Person ID,
|
3
|
+
GirlBoyfriendID int NULL,
|
4
|
+
-- Person is called Name,
|
5
|
+
Name varchar NOT NULL,
|
6
|
+
-- Person has Person ID,
|
7
|
+
PersonID int IDENTITY NOT NULL,
|
8
|
+
PRIMARY KEY(PersonID),
|
9
|
+
FOREIGN KEY (GirlBoyfriendID) REFERENCES Person (PersonID)
|
10
|
+
)
|
11
|
+
GO
|
12
|
+
|
13
|
+
CREATE VIEW dbo.GirlInPerson_BoyfriendID (GirlBoyfriendID) WITH SCHEMABINDING AS
|
14
|
+
SELECT GirlBoyfriendID FROM dbo.Person
|
15
|
+
WHERE GirlBoyfriendID IS NOT NULL
|
16
|
+
GO
|
17
|
+
|
18
|
+
CREATE UNIQUE CLUSTERED INDEX IX_GirlInPersonByGirlBoyfriendID ON dbo.GirlInPerson_BoyfriendID(GirlBoyfriendID)
|
19
|
+
GO
|
20
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
CREATE TABLE Person (
|
2
|
+
-- maybe Person is an Australian and maybe Australian has TFN,
|
3
|
+
AustralianTFN char(9) NULL,
|
4
|
+
-- maybe Person is an Employee and Employee has Employee ID,
|
5
|
+
EmployeeID int NULL,
|
6
|
+
-- Person has Person Name,
|
7
|
+
PersonName varchar NOT NULL,
|
8
|
+
PRIMARY KEY(PersonName)
|
9
|
+
)
|
10
|
+
GO
|
11
|
+
|
12
|
+
CREATE VIEW dbo.AustralianInPerson_TFN (AustralianTFN) WITH SCHEMABINDING AS
|
13
|
+
SELECT AustralianTFN FROM dbo.Person
|
14
|
+
WHERE AustralianTFN IS NOT NULL
|
15
|
+
GO
|
16
|
+
|
17
|
+
CREATE UNIQUE CLUSTERED INDEX IX_AustralianInPersonByAustralianTFN ON dbo.AustralianInPerson_TFN(AustralianTFN)
|
18
|
+
GO
|
19
|
+
|
20
|
+
CREATE VIEW dbo.EmployeeInPerson_ID (EmployeeID) WITH SCHEMABINDING AS
|
21
|
+
SELECT EmployeeID FROM dbo.Person
|
22
|
+
WHERE EmployeeID IS NOT NULL
|
23
|
+
GO
|
24
|
+
|
25
|
+
CREATE UNIQUE CLUSTERED INDEX PK_EmployeeInPerson ON dbo.EmployeeInPerson_ID(EmployeeID)
|
26
|
+
GO
|
27
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
CREATE TABLE AcceptableSubstitution (
|
2
|
+
-- Acceptable Substitution involves Product and Product has Product Name,
|
3
|
+
AlternateProductName varchar NOT NULL,
|
4
|
+
-- Acceptable Substitution involves Product and Product has Product Name,
|
5
|
+
ProductName varchar NOT NULL,
|
6
|
+
-- Acceptable Substitution involves Season,
|
7
|
+
Season varchar(6) NOT NULL CHECK(Season = 'Autumn' OR Season = 'Spring' OR Season = 'Summer' OR Season = 'Winter'),
|
8
|
+
PRIMARY KEY(ProductName, AlternateProductName, Season)
|
9
|
+
)
|
10
|
+
GO
|
11
|
+
|
12
|
+
CREATE TABLE Month (
|
13
|
+
-- Month has Month Nr,
|
14
|
+
MonthNr int NOT NULL CHECK((MonthNr >= 1 AND MonthNr <= 12)),
|
15
|
+
-- Month is in Season,
|
16
|
+
Season varchar(6) NOT NULL CHECK(Season = 'Autumn' OR Season = 'Spring' OR Season = 'Summer' OR Season = 'Winter'),
|
17
|
+
PRIMARY KEY(MonthNr)
|
18
|
+
)
|
19
|
+
GO
|
20
|
+
|
21
|
+
CREATE TABLE Product (
|
22
|
+
-- Product has Product Name,
|
23
|
+
ProductName varchar NOT NULL,
|
24
|
+
PRIMARY KEY(ProductName)
|
25
|
+
)
|
26
|
+
GO
|
27
|
+
|
28
|
+
CREATE TABLE ProductionForecast (
|
29
|
+
-- maybe Production Forecast predicts Cost,
|
30
|
+
Cost decimal NULL,
|
31
|
+
-- Production Forecast involves Product and Product has Product Name,
|
32
|
+
ProductName varchar NOT NULL,
|
33
|
+
-- Production Forecast involves Quantity,
|
34
|
+
Quantity int NOT NULL,
|
35
|
+
-- Production Forecast involves Refinery and Refinery has Refinery Name,
|
36
|
+
RefineryName varchar(80) NOT NULL,
|
37
|
+
-- Production Forecast involves Supply Period and Supply Period is in Month and Month has Month Nr,
|
38
|
+
SupplyPeriodMonthNr int NOT NULL CHECK((SupplyPeriodMonthNr >= 1 AND SupplyPeriodMonthNr <= 12)),
|
39
|
+
-- Production Forecast involves Supply Period and Supply Period is in Year and Year has Year Nr,
|
40
|
+
SupplyPeriodYearNr int NOT NULL,
|
41
|
+
PRIMARY KEY(RefineryName, SupplyPeriodYearNr, SupplyPeriodMonthNr, ProductName),
|
42
|
+
FOREIGN KEY (SupplyPeriodMonthNr) REFERENCES Month (MonthNr),
|
43
|
+
FOREIGN KEY (ProductName) REFERENCES Product (ProductName)
|
44
|
+
)
|
45
|
+
GO
|
46
|
+
|
47
|
+
CREATE TABLE Refinery (
|
48
|
+
-- Refinery has Refinery Name,
|
49
|
+
RefineryName varchar(80) NOT NULL,
|
50
|
+
PRIMARY KEY(RefineryName)
|
51
|
+
)
|
52
|
+
GO
|
53
|
+
|
54
|
+
CREATE TABLE Region (
|
55
|
+
-- Region has Region Name,
|
56
|
+
RegionName varchar NOT NULL,
|
57
|
+
PRIMARY KEY(RegionName)
|
58
|
+
)
|
59
|
+
GO
|
60
|
+
|
61
|
+
CREATE TABLE RegionalDemand (
|
62
|
+
-- Regional Demand involves Product and Product has Product Name,
|
63
|
+
ProductName varchar NOT NULL,
|
64
|
+
-- Regional Demand involves Quantity,
|
65
|
+
Quantity int NOT NULL,
|
66
|
+
-- Regional Demand involves Region and Region has Region Name,
|
67
|
+
RegionName varchar NOT NULL,
|
68
|
+
-- Regional Demand involves Supply Period and Supply Period is in Month and Month has Month Nr,
|
69
|
+
SupplyPeriodMonthNr int NOT NULL CHECK((SupplyPeriodMonthNr >= 1 AND SupplyPeriodMonthNr <= 12)),
|
70
|
+
-- Regional Demand involves Supply Period and Supply Period is in Year and Year has Year Nr,
|
71
|
+
SupplyPeriodYearNr int NOT NULL,
|
72
|
+
PRIMARY KEY(RegionName, SupplyPeriodYearNr, SupplyPeriodMonthNr, ProductName),
|
73
|
+
FOREIGN KEY (SupplyPeriodMonthNr) REFERENCES Month (MonthNr),
|
74
|
+
FOREIGN KEY (ProductName) REFERENCES Product (ProductName),
|
75
|
+
FOREIGN KEY (RegionName) REFERENCES Region (RegionName)
|
76
|
+
)
|
77
|
+
GO
|
78
|
+
|
79
|
+
CREATE TABLE TransportRoute (
|
80
|
+
-- maybe Transport Route incurs Cost per kl,
|
81
|
+
Cost decimal NULL,
|
82
|
+
-- Transport Route involves Refinery and Refinery has Refinery Name,
|
83
|
+
RefineryName varchar(80) NOT NULL,
|
84
|
+
-- Transport Route involves Region and Region has Region Name,
|
85
|
+
RegionName varchar NOT NULL,
|
86
|
+
-- Transport Route involves Transport Method,
|
87
|
+
TransportMethod varchar NOT NULL CHECK(TransportMethod = 'Rail' OR TransportMethod = 'Road' OR TransportMethod = 'Sea'),
|
88
|
+
PRIMARY KEY(TransportMethod, RefineryName, RegionName),
|
89
|
+
FOREIGN KEY (RefineryName) REFERENCES Refinery (RefineryName),
|
90
|
+
FOREIGN KEY (RegionName) REFERENCES Region (RegionName)
|
91
|
+
)
|
92
|
+
GO
|
93
|
+
|
94
|
+
ALTER TABLE AcceptableSubstitution
|
95
|
+
ADD FOREIGN KEY (AlternateProductName) REFERENCES Product (ProductName)
|
96
|
+
GO
|
97
|
+
|
98
|
+
ALTER TABLE AcceptableSubstitution
|
99
|
+
ADD FOREIGN KEY (ProductName) REFERENCES Product (ProductName)
|
100
|
+
GO
|
101
|
+
|
102
|
+
ALTER TABLE ProductionForecast
|
103
|
+
ADD FOREIGN KEY (RefineryName) REFERENCES Refinery (RefineryName)
|
104
|
+
GO
|
105
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
CREATE TABLE Party (
|
2
|
+
-- Party has Party Id,
|
3
|
+
PartyId int IDENTITY NOT NULL,
|
4
|
+
-- Party is involved in Party Moniker and Party Moniker has Accuracy and Accuracy has Accuracy Level,
|
5
|
+
PartyMonikerAccuracyLevel int NOT NULL CHECK((PartyMonikerAccuracyLevel >= 1 AND PartyMonikerAccuracyLevel <= 5)),
|
6
|
+
-- Party is involved in Party Moniker and Party Moniker involves Party Name,
|
7
|
+
PartyMonikerPartyName varchar NOT NULL,
|
8
|
+
-- maybe Party is a Person and Person is involved in Birth and maybe Birth was assisted by attending-Doctor and Doctor is a kind of Person and Person is a kind of Party and Party has Party Id,
|
9
|
+
PersonAttendingDoctorId int NULL,
|
10
|
+
-- maybe Party is a Person and Person is involved in Death and maybe Death occurred on death-Event Date and Event Date has ymd,
|
11
|
+
PersonDeathEventDateYmd datetime NULL,
|
12
|
+
-- maybe Party is a Person and Person is involved in Death,
|
13
|
+
PersonDied bit NULL,
|
14
|
+
-- maybe Party is a Person and Person is involved in Birth and Birth involves Event Date and Event Date has ymd,
|
15
|
+
PersonEventDateYmd datetime NULL,
|
16
|
+
PRIMARY KEY(PartyId),
|
17
|
+
FOREIGN KEY (PersonAttendingDoctorId) REFERENCES Party (PartyId)
|
18
|
+
)
|
19
|
+
GO
|
20
|
+
|
21
|
+
CREATE VIEW dbo.BirthInParty_PersonAttendingDoctorIdPersonEventDateYmd (PersonAttendingDoctorId, PersonEventDateYmd) WITH SCHEMABINDING AS
|
22
|
+
SELECT PersonAttendingDoctorId, PersonEventDateYmd FROM dbo.Party
|
23
|
+
WHERE PersonAttendingDoctorId IS NOT NULL
|
24
|
+
AND PersonEventDateYmd IS NOT NULL
|
25
|
+
GO
|
26
|
+
|
27
|
+
CREATE UNIQUE CLUSTERED INDEX PersonMustHaveSupertypeParty ON dbo.BirthInParty_PersonAttendingDoctorIdPersonEventDateYmd(PersonAttendingDoctorId, PersonEventDateYmd)
|
28
|
+
GO
|
29
|
+
|
@@ -0,0 +1,186 @@
|
|
1
|
+
CREATE TABLE Club (
|
2
|
+
-- Club has Club Code,
|
3
|
+
ClubCode varchar(6) NOT NULL,
|
4
|
+
-- Club is called Club Name,
|
5
|
+
ClubName varchar(32) NOT NULL,
|
6
|
+
PRIMARY KEY(ClubCode),
|
7
|
+
UNIQUE(ClubName)
|
8
|
+
)
|
9
|
+
GO
|
10
|
+
|
11
|
+
CREATE TABLE Entry (
|
12
|
+
-- Entry involves Course,
|
13
|
+
Course varchar(16) NOT NULL CHECK((Course >= 'A' AND Course <= 'E') OR Course = 'PW'),
|
14
|
+
-- Entry has Entry ID,
|
15
|
+
EntryID int IDENTITY NOT NULL,
|
16
|
+
-- Entry involves Event and Event has Event ID,
|
17
|
+
EventID int NOT NULL,
|
18
|
+
-- maybe Entry finished in finish-Placing,
|
19
|
+
FinishPlacing int NULL,
|
20
|
+
-- Entry involves Person and Person has Person ID,
|
21
|
+
PersonID int NOT NULL,
|
22
|
+
-- maybe Entry received Score,
|
23
|
+
Score int NULL,
|
24
|
+
PRIMARY KEY(EntryID),
|
25
|
+
UNIQUE(PersonID, EventID)
|
26
|
+
)
|
27
|
+
GO
|
28
|
+
|
29
|
+
CREATE TABLE Event (
|
30
|
+
-- Event is run by Club and Club has Club Code,
|
31
|
+
ClubCode varchar(6) NOT NULL,
|
32
|
+
-- Event has Event ID,
|
33
|
+
EventID int IDENTITY NOT NULL,
|
34
|
+
-- maybe Event is called Event Name,
|
35
|
+
EventName varchar(50) NULL,
|
36
|
+
-- Event uses Map and Map has Map ID,
|
37
|
+
MapID int NOT NULL,
|
38
|
+
-- maybe Event has Number,
|
39
|
+
Number int NULL CHECK((Number >= 1 AND Number <= 100)),
|
40
|
+
-- maybe Event is in Series and Series has Series ID,
|
41
|
+
SeriesID int NULL,
|
42
|
+
-- Event starts at start-Location,
|
43
|
+
StartLocation varchar(200) NOT NULL,
|
44
|
+
-- Event is held on Start Time,
|
45
|
+
StartTime datetime NOT NULL,
|
46
|
+
PRIMARY KEY(EventID),
|
47
|
+
FOREIGN KEY (ClubCode) REFERENCES Club (ClubCode)
|
48
|
+
)
|
49
|
+
GO
|
50
|
+
|
51
|
+
CREATE VIEW dbo.Event_Name (EventName) WITH SCHEMABINDING AS
|
52
|
+
SELECT EventName FROM dbo.Event
|
53
|
+
WHERE EventName IS NOT NULL
|
54
|
+
GO
|
55
|
+
|
56
|
+
CREATE UNIQUE CLUSTERED INDEX IX_EventByEventName ON dbo.Event_Name(EventName)
|
57
|
+
GO
|
58
|
+
|
59
|
+
CREATE VIEW dbo.Event_SeriesIDNumber (SeriesID, Number) WITH SCHEMABINDING AS
|
60
|
+
SELECT SeriesID, Number FROM dbo.Event
|
61
|
+
WHERE SeriesID IS NOT NULL
|
62
|
+
AND Number IS NOT NULL
|
63
|
+
GO
|
64
|
+
|
65
|
+
CREATE UNIQUE CLUSTERED INDEX IX_EventBySeriesIDNumber ON dbo.Event_SeriesIDNumber(SeriesID, Number)
|
66
|
+
GO
|
67
|
+
|
68
|
+
CREATE TABLE EventControl (
|
69
|
+
-- Event Control involves Control Number,
|
70
|
+
ControlNumber int NOT NULL CHECK((ControlNumber >= 1 AND ControlNumber <= 1000)),
|
71
|
+
-- Event Control involves Event and Event has Event ID,
|
72
|
+
EventID int NOT NULL,
|
73
|
+
-- maybe Event Control has Point Value,
|
74
|
+
PointValue int NULL,
|
75
|
+
PRIMARY KEY(EventID, ControlNumber),
|
76
|
+
FOREIGN KEY (EventID) REFERENCES Event (EventID)
|
77
|
+
)
|
78
|
+
GO
|
79
|
+
|
80
|
+
CREATE TABLE EventScoringMethod (
|
81
|
+
-- Event Scoring Method involves Course,
|
82
|
+
Course varchar(16) NOT NULL CHECK((Course >= 'A' AND Course <= 'E') OR Course = 'PW'),
|
83
|
+
-- Event Scoring Method involves Event and Event has Event ID,
|
84
|
+
EventID int NOT NULL,
|
85
|
+
-- Event Scoring Method involves Scoring Method,
|
86
|
+
ScoringMethod varchar(32) NOT NULL CHECK(ScoringMethod = 'Scatter' OR ScoringMethod = 'Score' OR ScoringMethod = 'Special'),
|
87
|
+
PRIMARY KEY(Course, EventID),
|
88
|
+
FOREIGN KEY (EventID) REFERENCES Event (EventID)
|
89
|
+
)
|
90
|
+
GO
|
91
|
+
|
92
|
+
CREATE TABLE Map (
|
93
|
+
-- maybe Map has Accessibility,
|
94
|
+
Accessibility char(1) NULL CHECK((Accessibility >= 'A' AND Accessibility <= 'D')),
|
95
|
+
-- Map has Map ID,
|
96
|
+
MapID int IDENTITY NOT NULL,
|
97
|
+
-- Map has Map Name,
|
98
|
+
MapName varchar(80) NOT NULL,
|
99
|
+
-- Map is owned by Club and Club has Club Code,
|
100
|
+
OwnerCode varchar(6) NOT NULL,
|
101
|
+
PRIMARY KEY(MapID),
|
102
|
+
UNIQUE(MapName),
|
103
|
+
FOREIGN KEY (OwnerCode) REFERENCES Club (ClubCode)
|
104
|
+
)
|
105
|
+
GO
|
106
|
+
|
107
|
+
CREATE TABLE Person (
|
108
|
+
-- maybe Person was born in birth-Year,
|
109
|
+
BirthYear int NULL CHECK((BirthYear >= 1900 AND BirthYear <= 3000)),
|
110
|
+
-- maybe Person is member of Club and Club has Club Code,
|
111
|
+
ClubCode varchar(6) NULL,
|
112
|
+
-- Person has Family Name,
|
113
|
+
FamilyName varchar(48) NOT NULL,
|
114
|
+
-- maybe Person is of Gender,
|
115
|
+
Gender char(1) NULL CHECK(Gender = 'F' OR Gender = 'M'),
|
116
|
+
-- Person has Given Name,
|
117
|
+
GivenName varchar(48) NOT NULL,
|
118
|
+
-- Person has Person ID,
|
119
|
+
PersonID int IDENTITY NOT NULL,
|
120
|
+
-- maybe Person has Post Code,
|
121
|
+
PostCode int NULL,
|
122
|
+
PRIMARY KEY(PersonID),
|
123
|
+
UNIQUE(GivenName, FamilyName),
|
124
|
+
FOREIGN KEY (ClubCode) REFERENCES Club (ClubCode)
|
125
|
+
)
|
126
|
+
GO
|
127
|
+
|
128
|
+
CREATE TABLE Punch (
|
129
|
+
-- Punch has Punch ID,
|
130
|
+
PunchID int IDENTITY NOT NULL,
|
131
|
+
PRIMARY KEY(PunchID)
|
132
|
+
)
|
133
|
+
GO
|
134
|
+
|
135
|
+
CREATE TABLE PunchPlacement (
|
136
|
+
-- Punch Placement involves Event Control and Event Control involves Event and Event has Event ID,
|
137
|
+
EventControlEventID int NOT NULL,
|
138
|
+
-- Punch Placement involves Event Control and Event Control involves Control Number,
|
139
|
+
EventControlNumber int NOT NULL,
|
140
|
+
-- Punch Placement involves Punch and Punch has Punch ID,
|
141
|
+
PunchID int NOT NULL,
|
142
|
+
PRIMARY KEY(PunchID, EventControlEventID, EventControlNumber),
|
143
|
+
FOREIGN KEY (EventControlEventID, EventControlNumber) REFERENCES EventControl (EventID, ControlNumber),
|
144
|
+
FOREIGN KEY (PunchID) REFERENCES Punch (PunchID)
|
145
|
+
)
|
146
|
+
GO
|
147
|
+
|
148
|
+
CREATE TABLE Series (
|
149
|
+
-- Series has Series Name,
|
150
|
+
Name varchar(40) NOT NULL,
|
151
|
+
-- Series has Series ID,
|
152
|
+
SeriesID int IDENTITY NOT NULL,
|
153
|
+
PRIMARY KEY(SeriesID),
|
154
|
+
UNIQUE(Name)
|
155
|
+
)
|
156
|
+
GO
|
157
|
+
|
158
|
+
CREATE TABLE Visit (
|
159
|
+
-- Visit involves Entry and Entry has Entry ID,
|
160
|
+
EntryID int NOT NULL,
|
161
|
+
-- Visit involves Punch and Punch has Punch ID,
|
162
|
+
PunchID int NOT NULL,
|
163
|
+
-- Visit involves Time,
|
164
|
+
Time datetime NOT NULL,
|
165
|
+
PRIMARY KEY(PunchID, EntryID, Time),
|
166
|
+
FOREIGN KEY (EntryID) REFERENCES Entry (EntryID),
|
167
|
+
FOREIGN KEY (PunchID) REFERENCES Punch (PunchID)
|
168
|
+
)
|
169
|
+
GO
|
170
|
+
|
171
|
+
ALTER TABLE Entry
|
172
|
+
ADD FOREIGN KEY (EventID) REFERENCES Event (EventID)
|
173
|
+
GO
|
174
|
+
|
175
|
+
ALTER TABLE Entry
|
176
|
+
ADD FOREIGN KEY (PersonID) REFERENCES Person (PersonID)
|
177
|
+
GO
|
178
|
+
|
179
|
+
ALTER TABLE Event
|
180
|
+
ADD FOREIGN KEY (MapID) REFERENCES Map (MapID)
|
181
|
+
GO
|
182
|
+
|
183
|
+
ALTER TABLE Event
|
184
|
+
ADD FOREIGN KEY (SeriesID) REFERENCES Series (SeriesID)
|
185
|
+
GO
|
186
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
CREATE TABLE Address (
|
2
|
+
-- Address has Address Id,
|
3
|
+
AddressId int IDENTITY NOT NULL,
|
4
|
+
-- maybe Address is in Legislative District and Legislative District has District Number,
|
5
|
+
LegislativeDistrictNumber int NULL,
|
6
|
+
-- maybe Address is in Legislative District and Legislative District is for State Or Province and State Or Province has State Or Province Id,
|
7
|
+
LegislativeDistrictStateOrProvinceId int NULL,
|
8
|
+
-- maybe Address is assigned Postal Code,
|
9
|
+
PostalCode int NULL,
|
10
|
+
-- maybe Address is in State Or Province and State Or Province has State Or Province Id,
|
11
|
+
StateOrProvinceId int NULL,
|
12
|
+
PRIMARY KEY(AddressId)
|
13
|
+
)
|
14
|
+
GO
|
15
|
+
|
16
|
+
CREATE TABLE Politician (
|
17
|
+
-- maybe Politician represents Legislative District and Legislative District has District Number,
|
18
|
+
LegislativeDistrictNumber int NULL,
|
19
|
+
-- maybe Politician represents Legislative District and Legislative District is for State Or Province and State Or Province has State Or Province Id,
|
20
|
+
LegislativeDistrictStateOrProvinceId int NULL,
|
21
|
+
-- Politician has Politician Id,
|
22
|
+
PoliticianId int IDENTITY NOT NULL,
|
23
|
+
PRIMARY KEY(PoliticianId)
|
24
|
+
)
|
25
|
+
GO
|
26
|
+
|
27
|
+
CREATE VIEW dbo.Politician_LegislativeDistrictNumberLegislativeDistrictStateOrProvinceId (LegislativeDistrictNumber, LegislativeDistrictStateOrProvinceId) WITH SCHEMABINDING AS
|
28
|
+
SELECT LegislativeDistrictNumber, LegislativeDistrictStateOrProvinceId FROM dbo.Politician
|
29
|
+
WHERE LegislativeDistrictNumber IS NOT NULL
|
30
|
+
AND LegislativeDistrictStateOrProvinceId IS NOT NULL
|
31
|
+
GO
|
32
|
+
|
33
|
+
CREATE UNIQUE CLUSTERED INDEX IX_PoliticianByLegislativeDistrictNumberLegislativeDistrictStateOrProvinceId ON dbo.Politician_LegislativeDistrictNumberLegislativeDistrictStateOrProvinceId(LegislativeDistrictNumber, LegislativeDistrictStateOrProvinceId)
|
34
|
+
GO
|
35
|
+
|
36
|
+
CREATE TABLE StateOrProvince (
|
37
|
+
-- State Or Province has State Or Province Id,
|
38
|
+
StateOrProvinceId int IDENTITY NOT NULL,
|
39
|
+
PRIMARY KEY(StateOrProvinceId)
|
40
|
+
)
|
41
|
+
GO
|
42
|
+
|
43
|
+
ALTER TABLE Address
|
44
|
+
ADD FOREIGN KEY (LegislativeDistrictStateOrProvinceId) REFERENCES StateOrProvince (StateOrProvinceId)
|
45
|
+
GO
|
46
|
+
|
47
|
+
ALTER TABLE Address
|
48
|
+
ADD FOREIGN KEY (StateOrProvinceId) REFERENCES StateOrProvince (StateOrProvinceId)
|
49
|
+
GO
|
50
|
+
|
51
|
+
ALTER TABLE Politician
|
52
|
+
ADD FOREIGN KEY (LegislativeDistrictStateOrProvinceId) REFERENCES StateOrProvince (StateOrProvinceId)
|
53
|
+
GO
|
54
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
CREATE TABLE SchoolActivity (
|
2
|
+
-- School Activity involves Activity and Activity has Activity Name,
|
3
|
+
ActivityName varchar(32) NOT NULL,
|
4
|
+
-- School Activity involves School and School has School Name,
|
5
|
+
SchoolName varchar NOT NULL,
|
6
|
+
PRIMARY KEY(SchoolName, ActivityName)
|
7
|
+
)
|
8
|
+
GO
|
9
|
+
|
10
|
+
CREATE TABLE Student (
|
11
|
+
-- Student is enrolled in School and School has School Name,
|
12
|
+
SchoolName varchar NOT NULL,
|
13
|
+
-- Student has Student Name,
|
14
|
+
StudentName varchar NOT NULL,
|
15
|
+
PRIMARY KEY(StudentName)
|
16
|
+
)
|
17
|
+
GO
|
18
|
+
|
19
|
+
CREATE TABLE StudentParticipation (
|
20
|
+
-- Student Participation involves Activity and Activity has Activity Name,
|
21
|
+
ActivityName varchar(32) NOT NULL,
|
22
|
+
-- Student Participation involves School and School has School Name,
|
23
|
+
SchoolName varchar NOT NULL,
|
24
|
+
-- Student Participation involves Student and Student has Student Name,
|
25
|
+
StudentName varchar NOT NULL,
|
26
|
+
PRIMARY KEY(StudentName, ActivityName),
|
27
|
+
FOREIGN KEY (StudentName) REFERENCES Student (StudentName)
|
28
|
+
)
|
29
|
+
GO
|
30
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
CREATE TABLE Claim (
|
2
|
+
-- Claim has Claim ID,
|
3
|
+
ClaimID int IDENTITY NOT NULL,
|
4
|
+
-- maybe Claim concerns Incident and maybe Incident occurred on Date Time,
|
5
|
+
IncidentDateTime datetime NULL,
|
6
|
+
-- maybe Claim concerns Incident and maybe Incident was independently witnessed by Witness and Witness is a kind of Person and Person has Person Name,
|
7
|
+
IncidentWitnessName varchar NULL,
|
8
|
+
PRIMARY KEY(ClaimID)
|
9
|
+
)
|
10
|
+
GO
|
11
|
+
|
12
|
+
CREATE TABLE Person (
|
13
|
+
-- Person has Person Name,
|
14
|
+
PersonName varchar NOT NULL,
|
15
|
+
PRIMARY KEY(PersonName)
|
16
|
+
)
|
17
|
+
GO
|
18
|
+
|
19
|
+
CREATE TABLE VehicleIncident (
|
20
|
+
-- maybe Vehicle Incident occurred while Driver was in charge and Driver is a kind of Person and Person has Person Name,
|
21
|
+
DriverName varchar NULL,
|
22
|
+
-- Vehicle Incident is a kind of Incident and Incident resulted in Claim and Claim has Claim ID,
|
23
|
+
IncidentClaimID int NOT NULL,
|
24
|
+
PRIMARY KEY(IncidentClaimID),
|
25
|
+
FOREIGN KEY (IncidentClaimID) REFERENCES Claim (ClaimID),
|
26
|
+
FOREIGN KEY (DriverName) REFERENCES Person (PersonName)
|
27
|
+
)
|
28
|
+
GO
|
29
|
+
|
30
|
+
ALTER TABLE Claim
|
31
|
+
ADD FOREIGN KEY (IncidentWitnessName) REFERENCES Person (PersonName)
|
32
|
+
GO
|
33
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
CREATE TABLE Company (
|
2
|
+
-- Company is run by CEO and CEO is a kind of Manager and Manager is a kind of Employee and Employee works for Company and Company has CompanyName,
|
3
|
+
CEOCompanyName varchar NOT NULL,
|
4
|
+
-- Company is run by CEO and CEO is a kind of Manager and Manager is a kind of Employee and Employee has EmployeeNr,
|
5
|
+
CEOEmployeeNr int NOT NULL,
|
6
|
+
-- Company has CompanyName,
|
7
|
+
CompanyName varchar NOT NULL,
|
8
|
+
PRIMARY KEY(CompanyName)
|
9
|
+
)
|
10
|
+
GO
|
11
|
+
|
12
|
+
CREATE TABLE Employee (
|
13
|
+
-- Employee works for Company and Company has CompanyName,
|
14
|
+
CompanyName varchar NOT NULL,
|
15
|
+
-- Employee has EmployeeNr,
|
16
|
+
EmployeeNr int NOT NULL,
|
17
|
+
-- maybe Employee reports to Manager and Manager is a kind of Employee and Employee works for Company and Company has CompanyName,
|
18
|
+
ManagerCompanyName varchar NULL,
|
19
|
+
-- maybe Employee reports to Manager and Manager is a kind of Employee and Employee has EmployeeNr,
|
20
|
+
ManagerEmployeeNr int NULL,
|
21
|
+
PRIMARY KEY(CompanyName, EmployeeNr),
|
22
|
+
FOREIGN KEY (CompanyName) REFERENCES Company (CompanyName),
|
23
|
+
FOREIGN KEY (ManagerCompanyName, ManagerEmployeeNr) REFERENCES Employee (CompanyName, EmployeeNr)
|
24
|
+
)
|
25
|
+
GO
|
26
|
+
|
27
|
+
ALTER TABLE Company
|
28
|
+
ADD FOREIGN KEY (CEOCompanyName, CEOEmployeeNr) REFERENCES Employee (CompanyName, EmployeeNr)
|
29
|
+
GO
|
30
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
CREATE TABLE Event (
|
2
|
+
-- Event has Event Id,
|
3
|
+
EventId int IDENTITY NOT NULL,
|
4
|
+
-- Event is held at Venue and Venue has Venue Id,
|
5
|
+
VenueId int NOT NULL,
|
6
|
+
PRIMARY KEY(EventId)
|
7
|
+
)
|
8
|
+
GO
|
9
|
+
|
10
|
+
CREATE TABLE Seat (
|
11
|
+
-- Seat has Number,
|
12
|
+
Number smallint NOT NULL,
|
13
|
+
-- Seat is in Reserve and Reserve has Reserve Name,
|
14
|
+
ReserveName varchar NOT NULL,
|
15
|
+
-- Seat is in Row and Row has Row Code,
|
16
|
+
RowCode char NOT NULL,
|
17
|
+
-- Seat is at Venue and Venue has Venue Id,
|
18
|
+
VenueId int NOT NULL,
|
19
|
+
PRIMARY KEY(VenueId, ReserveName, RowCode, Number)
|
20
|
+
)
|
21
|
+
GO
|
22
|
+
|
23
|
+
CREATE TABLE Ticket (
|
24
|
+
-- Ticket is for Event and Event has Event Id,
|
25
|
+
EventId int NOT NULL,
|
26
|
+
-- Ticket is for Seat and Seat has Number,
|
27
|
+
SeatNumber smallint NOT NULL,
|
28
|
+
-- Ticket is for Seat and Seat is in Reserve and Reserve has Reserve Name,
|
29
|
+
SeatReserveName varchar NOT NULL,
|
30
|
+
-- Ticket is for Seat and Seat is in Row and Row has Row Code,
|
31
|
+
SeatRowCode char NOT NULL,
|
32
|
+
-- Ticket is for Seat and Seat is at Venue and Venue has Venue Id,
|
33
|
+
SeatVenueId int NOT NULL,
|
34
|
+
PRIMARY KEY(EventId, SeatVenueId, SeatReserveName, SeatRowCode, SeatNumber),
|
35
|
+
FOREIGN KEY (EventId) REFERENCES Event (EventId),
|
36
|
+
FOREIGN KEY (SeatVenueId, SeatReserveName, SeatRowCode, SeatNumber) REFERENCES Seat (VenueId, ReserveName, RowCode, Number)
|
37
|
+
)
|
38
|
+
GO
|
39
|
+
|
40
|
+
CREATE TABLE Venue (
|
41
|
+
-- Venue has Venue Id,
|
42
|
+
VenueId int IDENTITY NOT NULL,
|
43
|
+
PRIMARY KEY(VenueId)
|
44
|
+
)
|
45
|
+
GO
|
46
|
+
|
47
|
+
ALTER TABLE Event
|
48
|
+
ADD FOREIGN KEY (VenueId) REFERENCES Venue (VenueId)
|
49
|
+
GO
|
50
|
+
|
51
|
+
ALTER TABLE Seat
|
52
|
+
ADD FOREIGN KEY (VenueId) REFERENCES Venue (VenueId)
|
53
|
+
GO
|
54
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
CREATE TABLE Meal (
|
2
|
+
-- Meal has MealId,
|
3
|
+
MealId int IDENTITY NOT NULL,
|
4
|
+
PRIMARY KEY(MealId)
|
5
|
+
)
|
6
|
+
GO
|
7
|
+
|
8
|
+
CREATE TABLE Service (
|
9
|
+
-- maybe Service earned a tip of Amount and Amount has AUDValue,
|
10
|
+
AmountAUDValue decimal NULL,
|
11
|
+
-- Service involves Meal and Meal has MealId,
|
12
|
+
MealId int NOT NULL,
|
13
|
+
-- Service involves Waiter and Waiter has WaiterNr,
|
14
|
+
WaiterNr int NOT NULL,
|
15
|
+
PRIMARY KEY(WaiterNr, MealId),
|
16
|
+
FOREIGN KEY (MealId) REFERENCES Meal (MealId)
|
17
|
+
)
|
18
|
+
GO
|
19
|
+
|
20
|
+
CREATE TABLE WaiterTip (
|
21
|
+
-- WaiterTip involves Amount and Amount has AUDValue,
|
22
|
+
AmountAUDValue decimal NOT NULL,
|
23
|
+
-- WaiterTip involves Meal and Meal has MealId,
|
24
|
+
MealId int NOT NULL,
|
25
|
+
-- WaiterTip involves Waiter and Waiter has WaiterNr,
|
26
|
+
WaiterNr int NOT NULL,
|
27
|
+
PRIMARY KEY(WaiterNr, MealId),
|
28
|
+
FOREIGN KEY (MealId) REFERENCES Meal (MealId)
|
29
|
+
)
|
30
|
+
GO
|
31
|
+
|