473,830 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Correct Schema for this business problem?

I need help modeling schema for a particular issue that i've never run
across before. And for the life of me, I cannot figure out how to model
it - at least in a way that feels correct. Please let me know if I need
to post this else where.

Here are the tables:

Reservation <------------Customer_Reserv ation <--------->Customers

GolfCourses <--------------Customer_Golfin g
TeeTimes <------------------Customer_TeeTim e
Ok so here is the business rules. A reservation will be assigned one or
more customers. A reservation has one or more golfcourses. Golfcourses
will be assigned people. These people can only come from those people
assigned to the reservation that the golfcourse belongs to. GolfCourses
have one or more teetimes. TeeTimes will be assigned people. Those
people can come from only the people assigned to the golfcourse that
the teetime belongs to.

Basically, how can I setup the schema to enforce the business rules? I
can see only to do this at the application level. Maybe I have modeled
this incorrectly?

Jan 16 '07 #1
8 1303
Blast wrote:
I need help modeling schema for a particular issue that i've never run
across before. And for the life of me, I cannot figure out how to model
it - at least in a way that feels correct. Please let me know if I need
to post this else where.

Here are the tables:

Reservation <------------Customer_Reserv ation <--------->Customers

GolfCourses <--------------Customer_Golfin g
TeeTimes <------------------Customer_TeeTim e
Ok so here is the business rules. A reservation will be assigned one or
more customers. A reservation has one or more golfcourses. Golfcourses
will be assigned people. These people can only come from those people
assigned to the reservation that the golfcourse belongs to. GolfCourses
have one or more teetimes. TeeTimes will be assigned people. Those
people can come from only the people assigned to the golfcourse that
the teetime belongs to.

Basically, how can I setup the schema to enforce the business rules? I
can see only to do this at the application level. Maybe I have modeled
this incorrectly?
You didn't specify any keys so this is pure speculation:

CREATE TABLE CustomerReserva tions
(CustomerNo INT NOT NULL REFERENCES Customers (CustomerNo),
ReservationNo INT NOT NULL REFERENCES Reservations (ReservationNo) ,
PRIMARY KEY (CustomerNo,Res ervationNo));

CREATE TABLE CourseReservati ons
(CourseNo INT NOT NULL REFERENCES Courses (CourseNo),
ReservationNo INT NOT NULL REFERENCES Reservations (ReservationNo) ,
PRIMARY KEY (CourseNo,Reser vationNo));

CREATE TABLE CustomerCourseR eservations
(CustomerNo INT NOT NULL,
CourseNo INT NOT NULL,
ReservationNo INT NOT NULL,
FOREIGN KEY (CourseNo,Reser vationNo) REFERENCES CourseReservati ons,
FOREIGN KEY (CustomerNo,Res ervationNo) REFERENCES
CustomerReserva tions);

.... etc

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Jan 16 '07 #2

Blast wrote:
I need help modeling schema for a particular issue that i've never run
across before. And for the life of me, I cannot figure out how to model
it - at least in a way that feels correct. Please let me know if I need
to post this else where.

Here are the tables:

Reservation <------------Customer_Reserv ation <--------->Customers

GolfCourses <--------------Customer_Golfin g
TeeTimes <------------------Customer_TeeTim e
Ok so here is the business rules. A reservation will be assigned one or
more customers. A reservation has one or more golfcourses. Golfcourses
will be assigned people. These people can only come from those people
assigned to the reservation that the golfcourse belongs to. GolfCourses
have one or more teetimes. TeeTimes will be assigned people. Those
people can come from only the people assigned to the golfcourse that
the teetime belongs to.

Basically, how can I setup the schema to enforce the business rules? I
can see only to do this at the application level. Maybe I have modeled
this incorrectly?
You might get more help after you have posted your CREATE TABLE
statements. Make sure your constraints are included.

-----------------------
Alex Kuznetsov
http://sqlserver-tips.blogspot.com/
http://sqlserver-puzzles.blogspot.com/

Jan 16 '07 #3
Ok, i drew out your diagram and my design thoughts are exactly like
yours. And I was hoping it wouldn't be.
Let me explain. I'm using the windows form (.net) for my UI and there
are no controls that recognize this pattern, at least not right out of
the box (not to my knowledge).

For example, for the CourseReservati ons I want to have a comboBox that
lists all Customers in the reservation (CusomterReserv ations). Then
next to the customers name would be a checkbox, which would represent
existance of data entered into the CustomerCourseR eservation. When you
toggle on and off the checkbox it would delete or add the entry into
the CustomerCourseR eservations.

So. thats what I need to do keeping this schema. I was hoping I had
incorrectly created the schema and there was an easier way to model the
problem.

Thanks for your reply.

Jan 16 '07 #4


http://www.condoresorts.com/Problem.jpg

With a capital P

Jan 17 '07 #6
Blast wrote:
Ok, i drew out your diagram and my design thoughts are exactly like
yours. And I was hoping it wouldn't be.
Let me explain. I'm using the windows form (.net) for my UI and there
are no controls that recognize this pattern, at least not right out of
the box (not to my knowledge).
Obviously the UI code has nothing to do with constructing an effective
data model. The right solutions rarely come "out of the box".

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Jan 17 '07 #7
>I need help modeling schema for a particular issue that i've never run across before. <<

I looked at your ER diagram. A good rule of thumb is that when it has
a cycle in it, you are in trouble. You also defined a lot of MVDs
which guarantee 5NF problems. You will also have what Tom Johnston
calls non-normal form redundancies. And the golf courses never appears
in the diagram.

I also had problems with your business rules:
> A reservation will be assigned one or more customers.
A reservation has one or more golfcourses. <<

Shouldn't a reservation put a group of cusotmers onto the SAME golf
course? You allow 5 poeple to play as a reservation on 10 different
courses.
>Golfcourses will be assigned people. <<
Shouldn't that be the other way around? So I do not need a reservation
at all because I have my own course?
>These people can only come from those people assigned to the reservation that the golfcourse belongs to. <<
Very convoluted and inside out.
>GolfCourses have one or more teetimes. <<
No, a golf course has 18 holes with a par for each hole, etc. A
reservation is an event and events have times; a golf course is an
eneity and they have existence.
>TeeTimes will be assigned people. <<
So everyone in a resrevation can tee off at a different time, as well
as not beingon the same course?
>Those people can come from only the people assigned to the golfcourse that the teetime belongs to.<<
Very convoluted and inside out again.
>Maybe I have modeled this incorrectly? <<
Yes. Let's try this:

A) Each reservation has
1) a single golf course - manditory
2) a single tee time - manditory
3) one or more customers - manditory
4) Reservations are identified by course and tee time

CREATE TABLE Customers
(customer_id INTEGER NOT NULL PRIMARY KEY,
customer_name VARCHAR(25) NOT NULL,
etc);

CREATE TABLE Golfcourses
(golfcourse_id CHAR(5) NOT NULL PRIMARY KEY,
golfcourse_name VARCHAR(25) NOT NULL,
etc.);

CREATE TABLE Parties
(party_name CHAR(25) NOT NULL PRIMARY KEY
customer_id INTEGER NOT NULL
REFERENCES Customers (customer_id)
ON UPDATE CASACDE
ON DELETE CASACDE,
etc.);

CREATE TABLE Reservations
(golfcourse_id CHAR(5) NOT NULL
REFERENCES Golfcourses (golfcourse_id)
tee_time DATETIME NOT NULL,
party_name CHAR(25) NOT NULL
REFERENCES Parties (party_name)
ON UPDATE CASACDE
ON DELETE CASACDE,
PRIMARY KEY (golfcourse_id, tee_time));

A) I would think about getting the count of golfers ahead of your
current reservation and using a look-up table to compute the tee time
since you expect a larger party to play slower than a small one. You
can refine the estimates with actual data later.

Old joke:
wife to husband coming home from golf game: "You're back late! You go
out drinking?"
husband: "No. Eddie had a massive heart attack on the third hole."
wife: "I'm soory! That must have been awful!"
husband: "It was! What with hitting the ball and dragging the body, I
thought I'd never finish before sundown."

B) You will have to create a customer first, so I would allow for his
guests in the customer id scheme, thus:
12300 = 'Bobby Jones"
12301 = 'Bobby Jones - guest #1"
etc.
12312 = 'Bobby Jones - guest #12" or whatever the guest limit is

C) Since people tend to play with a regular group of friends (or
enemies), you build the Parties table entry next and retain them for
re-use. A single player is a party of one. You will need dummy party
identifiers to construct any ad hoc situations that might come up.

Does this do what you wanted?

Jan 17 '07 #8
Well thanks for the reply. BUT. There is a reason why we want things
done the way we want things done. Let me explain.
I looked at your ER diagram. A good rule of thumb is that when it has
a cycle in it, you are in trouble. You also defined a lot of MVDs
which guarantee 5NF problems. You will also have what Tom Johnston
calls non-normal form redundancies. And the golf courses never appears
in the diagram.
What are MVD's? We need the cycle. The problem is, we don't book the
golf directly. We're not a golf course. People who are in a reservation
don't always play golf. So, we assign people to a reservation. Some of
those people in the reservation might be playing golf, but they must be
in the reservation to play golf. Also, the tee times need be confirmed.
This isn't automatically done. So, we want to make sure the people
assigned to the golf course have tee times made. If they have no tee
times, then we need to be able to query that information becuase
someone needs to call the golf course and make the tee times.

A reservation will be assigned one or more customers.
A reservation has one or more golfcourses. <<
No, it has 0 or more.

Shouldn't a reservation put a group of cusotmers onto the SAME golf
course? You allow 5 poeple to play as a reservation on 10 different
courses.
Yeah, some people in the reservation will be playing golf, some won't.
2 people in the reservation might be playing 10 different golf courses.

Golfcourses will be assigned people. <<

Shouldn't that be the other way around? So I do not need a reservation
at all because I have my own course?
Yeah, we don't have our own course.

These people can only come from those people assigned to the reservation that the golfcourse belongs to.
Very convoluted and inside out.<<
Why is this inside out?

GolfCourses have one or more teetimes. <<

No, a golf course has 18 holes with a par for each hole, etc. A
reservation is an event and events have times; a golf course is an
eneity and they have existence.
Tee times are made in groups of 3 or 4 typically. So if you have a big
group, lets say 36 players you need many tee times.
TeeTimes will be assigned people. <<

So everyone in a resrevation can tee off at a different time, as well
as not beingon the same course?
Yes, that's right.

Those people can come from only the people assigned to the golfcourse that the teetime belongs to.<<

Very convoluted and inside out again.
Yes this is right. You see, someone will put people in a reservation.
Weeks later can go by. Then, someone from that group might call in and
say, we want to play 3 different golf courses and we need these tee
times. But we can't give them tee times right away because maybe they
are reserving more then a year in a advance. So, we assign them to the
golf course and eventually make their tee times.
You see, I want to be able to query, how many reservations do we have
with people who aren't playing golf. How many people in reservations do
we have who are playing golf but dont have tee times. How do I answer
these questions with the ER diagram you gave me? I can't!

Let me further explain the business just in case anyone wants to
comment.

People make a reservation with us. We book golf, rental cars, other
activities, and rooms. Some people book and get a room, some people
book and just play golf through us. Some people just play activities
through us etc. So the relationship for these items are zero or more.
Since we don't actually own any of these items we have to first assign
people to the item and then assign them a time in which they are
confirmed for the event. We want to know who's assigned what, and then
who actually has been confirmed by the companies the event time.

So we start off by creating a group of people that belong to the
reservation. Then as they decide what they want to do, we start
assigning them different items. Those items need to have things
confirmed by third party organizations. Does that make sense?

Jan 18 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2856
by: Mike | last post by:
Note: My XML experience to date has (unfortunately) been limited to reading and thinking, rather than implementation. Anyway, I am in the process of trying to figure out the most efficient way to validate and transform some very large (potentially over 100MB) XML documents. This is related to another question I will post next, but for now, I want to focus on one particular topic. The data in question has particular business rules...
0
10748
by: Sarah Tegtmeier | last post by:
Hi I have a question about the correct use of the attribute xsi:schemaLocation. My programm has to process XML files where the value of this attribute causes some problems. The programm is written in C++ using Xerces C++ version 2.3.0. An older older version of the programm used Xerces C++ version 1.6.0. The XML files look like the following example:
4
2512
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set of projects. Therefore, I wish to include the project customType in the projectCollection namespace. I therefore have declared two xsd documents: project.xsd and projectcollection.xsd
0
1393
by: Vish | last post by:
I am trying to use xmldatadocument to load an xml file.The xml has the data as attributes, the datadocument is able to successfully parse the document into the tables and shows the right column count but does not add any rows. I tried validating the schema everything is fine but no data is returned . I have attached the sample xml file and schema. Any help is appreciated . Thanks! <SiebelMessage CallingApp="COM" ErrorMsg="" ErrorCode=""...
2
1286
by: John Jenkins | last post by:
Hi, I have a lot of schemas to load into a schema collection. I load them in by reading each one into a XMLTextReader from disk and add them into a schema collection. I have a couple of issues to contend with. 1. The targetnamespace on all the schemas (except ones which define generic types) are the same. 2. The DefaultNamespace is the same as the Targetnamespace (I think this should be ok) 3. Some of the schemas import other sschemas...
1
1481
by: Ashish | last post by:
Is it possible to get the xml schema of a custom business object, and i am just interested in getting that particular complex type :) for exaample if i have a clas like public class Person{ private string fname; private string lname; public string FirstName
1
1112
by: MuZZy | last post by:
Hi, I'm going to develop a pretty simple document management application and i want to use WCF to connect back-end to smart client front-end. That application will allow to create a hierarchcal structure where any node can be linked with a document file, which are all stored in a SQL Server database. I'm trying to convince my boss towards smartclient instead of ASP.NET
0
1809
by: Steve Elliott | last post by:
When you link an ObjectDataSource to a business object, it appears that the Refresh Schema button does nothing. Here's the scenario: I have two class libraries, one is a Data Access Layer and the other is a List class. The former implements all of the CRUD logic, and the latter implements a number of interfaces for the purpose of aggregate functionality. For example, the following is the method I select when I configure the object...
5
2888
by: Frank Millman | last post by:
Hi all This is not strictly a Python question, but as I am writing in Python, and as I know there are some XML gurus on this list, I hope it is appropriate here. XML-schemas are used to define the structure of an xml document, and to validate that a particular document conforms to the schema. They can also be used to transform the document, by filling in missing attributes with default values.
0
9793
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10774
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10491
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10526
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10206
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9315
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.