Showing posts with label design. Show all posts
Showing posts with label design. Show all posts

Tuesday, March 20, 2012

A tool for aggregation design XMLA file viewing/editing ?

Is the best way to specify the most useful aggregations to actually edit the XMLA for measure group and hand pick the aggregations I need?

In that case has anyone seen a basic tool for viewing the attributes in each aggregation and perh
In taht case has aaps even deleting them/editing the XMLA file a little bit? The reason I am looking for a tool is to make sense out of 2000 aggregations created by the wizard.

A new sample app for viewing and editing aggregations should become available as part of SP2...

Thanks,

Akshai

|||what is the name of that sample? I have SP2 final, but only samples under Microsoft SQL Server\90\Sample\Analysis Services are:

\Administrator\ActivityViewer
\DataMining\Data Mining Web Controls
\DataMining\SQL Server Data Mining Plug-In Algorithms
\Programmability\AMO
\Tutorials\Lesson4
\Tutorials\Lesson7

I checked the Programmability\AMO sample, but all it does is provide drilldown into properties. I can drill into aggregations but it's very laborious to use to find see which attributes each aggregation aggregates, because you would need to click 2 times on each dimention in each aggregation to see which attributes it affects. I did not see an ability to create a new aggregation or change an aggregation.

Did I miss something?
Where is the sample that Edward and you mention ?

|||

It's called AggregationManager and is under Administrator/AggregationManager.

I don't think the samples are included in the main SP2 download. I think you have to download them separately. The SQL Server sample are now all available from codeplex. The download page for the SSAS samples is here http://www.codeplex.com/MSFTASProdSamples/Release/ProjectReleases.aspx?ReleaseId=2461

The AggManager sample only works with a deployed database. I am looking to add support for this tool directly in BIDS through a project I am working on at www.codeplex.com/BIDSHelper. I hope to get an initial beta release out in the next week or two if you are interested.

A tool for aggregation design XMLA file viewing/editing ?

Is the best way to specify the most useful aggregations to actually edit the XMLA for measure group and hand pick the aggregations I need?

In that case has anyone seen a basic tool for viewing the attributes in each aggregation and perh
In taht case has aaps even deleting them/editing the XMLA file a little bit? The reason I am looking for a tool is to make sense out of 2000 aggregations created by the wizard.

A new sample app for viewing and editing aggregations should become available as part of SP2...

Thanks,

Akshai

|||what is the name of that sample? I have SP2 final, but only samples under Microsoft SQL Server\90\Sample\Analysis Services are:

\Administrator\ActivityViewer
\DataMining\Data Mining Web Controls
\DataMining\SQL Server Data Mining Plug-In Algorithms
\Programmability\AMO
\Tutorials\Lesson4
\Tutorials\Lesson7

I checked the Programmability\AMO sample, but all it does is provide drilldown into properties. I can drill into aggregations but it's very laborious to use to find see which attributes each aggregation aggregates, because you would need to click 2 times on each dimention in each aggregation to see which attributes it affects. I did not see an ability to create a new aggregation or change an aggregation.

Did I miss something?
Where is the sample that Edward and you mention ?|||

It's called AggregationManager and is under Administrator/AggregationManager.

I don't think the samples are included in the main SP2 download. I think you have to download them separately. The SQL Server sample are now all available from codeplex. The download page for the SSAS samples is here http://www.codeplex.com/MSFTASProdSamples/Release/ProjectReleases.aspx?ReleaseId=2461

The AggManager sample only works with a deployed database. I am looking to add support for this tool directly in BIDS through a project I am working on at www.codeplex.com/BIDSHelper. I hope to get an initial beta release out in the next week or two if you are interested.

Sunday, March 11, 2012

A Smart Way to Design a Database for Companies, People, Addresses?

I have a database design question. I am dealing with a bunch of
standard content categories: people, addresses and companies. I don't
know whether I should have a table for each type of data and associate
addresses (via join tables) with people or companies or both; or
whether the companies table and the people tables should both include
address info. How far does one usually go to normalize these standard
types of data?
Sure, you could say that it depends on the specific business logic,
but I am curious if anyone out there has a way of normalizing this
type of data that has proven effective for most applications. I'm not
sure how our app will grow over time and therefore I want to
accommodate unforeseen requirements upfront without wasting untold
hours on far edge cases. Should I just bite the bullet and assume
we'll need a many-to-many relationship for each?
Any advice or suggested reading would be much appreciated.>> How far does one usually go to normalize these standard types of data?
First of all there are no "standard types" of data. Every piece of data one
deals with during logical modeling depends on the conceptual model and
business rule. Of course, you could find certain aspects of commonality
among models, but relying on them as certain patterns is often a bad
approach.
In general, normalization beyond 1NF is the process of reducing certain
types of redundancies and removing database bias. In the process certain
known problems like update/delete anomalies are elimination. Overall, this
leads to a better quality design. Therefore the answer to your question is
you go as far as you want to keep your database redundancy-free.
>> Sure, you could say that it depends on the specific business logic, but I
>> am curious if anyone out there has a way of normalizing this type of data
>> that has proven effective for most applications.
There are many who claim (universal models, b-patterns etc. for more, google
for David Hayes or Len Silverston) that this is possible, but many
recognized scholars and experts in the database field are not in favor of
such approaches.
>> I'm not sure how our app will grow over time and therefore I want to
>> accommodate unforeseen requirements upfront without wasting untold hours
>> on far edge cases. Should I just bite the bullet and assume we'll need a
>> many-to-many relationship for each?
Expecting the worst is often the wisest policy :-)
--
Anith|||For efficiency's sake it is common practice design such tables with the
address (and often contact) information of the entity (Business, Employee,
Customer, etc) contained within the main entity table.
"Chris" <christopher.b.lewis@.gmail.com> wrote in message
news:1191611766.490849.42420@.50g2000hsm.googlegroups.com...
>I have a database design question. I am dealing with a bunch of
> standard content categories: people, addresses and companies. I don't
> know whether I should have a table for each type of data and associate
> addresses (via join tables) with people or companies or both; or
> whether the companies table and the people tables should both include
> address info. How far does one usually go to normalize these standard
> types of data?
> Sure, you could say that it depends on the specific business logic,
> but I am curious if anyone out there has a way of normalizing this
> type of data that has proven effective for most applications. I'm not
> sure how our app will grow over time and therefore I want to
> accommodate unforeseen requirements upfront without wasting untold
> hours on far edge cases. Should I just bite the bullet and assume
> we'll need a many-to-many relationship for each?
> Any advice or suggested reading would be much appreciated.
>|||> For efficiency's sake it is common practice design such tables with the
> address (and often contact) information of the entity (Business, Employee,
> Customer, etc) contained within the main entity table.
But this quickly changes if the app requires separate addresses for mailing,
shipping, billing, physical, etc. And then when a company can have multiple
branches the schema becomes even more complex.
Same is true for an employee, or a customer, if multiple addresses are
possible then the main entity table is out of the question. Consider Amazon
or PayPal, where you can store as many addresses as you like. I'm not sure
what their upper bound is (and haven't tried), but I think I have 5 on
PayPal, and it's highly doubtful they have a table like this:
CREATE TABLE dbo.Customers
(
FirstName,
LastName,
PrimaryAddress1,
PrimaryAddress2,
PrimaryCity,
PrimaryRegion,
PrimaryZip,
SecondaryAddress1,
...,
SecondaryZip,
TertiaryAddress1,
...,
TertiaryZip,
/*
etc.
etc.
*/
);
A|||>> Same is true for an employee, or a customer, if multiple addresses are
>> possible then the main entity table is out of the question. Consider
>> Amazon or PayPal, where you can store as many addresses as you like.
That is almost an universal requirement these days with many financial
institutions too. While it is hard to generalize, one pattern for a commonly
occurring entity class like customer is to have 3 core m:n relationship
designations in the schema,
-- the core customer entity:
name, ssn, passport_nbr, drivers_license etc.
-- the locality:
address, state, zip, region, country etc.
-- the contact/communication information:
phone_nbr, email_address, icq/mkt/linkedin etc.
One book I recently read, Data Model Patterns by D. Hay emphasizes on this
approach. His line of thought is mostly on the Zachman Framework to derive
at this common pattern and provides some reasonable justifications to adopt
it as a baseline. The UDM folks also have a similar approach :
http://www.univdata.com/images/sep98752-fig6.gif
--
Anith|||>Should I just bite the bullet and assume we'll need a many-to-many
>relationship for each?
Yes. Some years back I fell into the "put the address in the base table"
trap.
People -< PeopleCompany >- Companies
| |
^ ^
PeopleAddresses CompanyAddresses
Y Y
| |
Addresses >-- AddressTypes
"Chris" <christopher.b.lewis@.gmail.com> wrote in message
news:1191611766.490849.42420@.50g2000hsm.googlegroups.com...
>I have a database design question. I am dealing with a bunch of
> standard content categories: people, addresses and companies. I don't
> know whether I should have a table for each type of data and associate
> addresses (via join tables) with people or companies or both; or
> whether the companies table and the people tables should both include
> address info. How far does one usually go to normalize these standard
> types of data?
> Sure, you could say that it depends on the specific business logic,
> but I am curious if anyone out there has a way of normalizing this
> type of data that has proven effective for most applications. I'm not
> sure how our app will grow over time and therefore I want to
> accommodate unforeseen requirements upfront without wasting untold
> hours on far edge cases. Should I just bite the bullet and assume
> we'll need a many-to-many relationship for each?
> Any advice or suggested reading would be much appreciated.
>|||On Fri, 05 Oct 2007 12:16:06 -0700, Chris
<christopher.b.lewis@.gmail.com> wrote:
>I have a database design question. I am dealing with a bunch of
>standard content categories: people, addresses and companies. I don't
>know whether I should have a table for each type of data and associate
>addresses (via join tables) with people or companies or both; or
>whether the companies table and the people tables should both include
>address info. How far does one usually go to normalize these standard
>types of data?
The more time you spend with databases, the more you tend to factor
things into 3NF or better as a default. Break out the addresses!
>Sure, you could say that it depends on the specific business logic,
>but I am curious if anyone out there has a way of normalizing this
>type of data that has proven effective for most applications. I'm not
>sure how our app will grow over time and therefore I want to
>accommodate unforeseen requirements upfront without wasting untold
>hours on far edge cases. Should I just bite the bullet and assume
>we'll need a many-to-many relationship for each?
>Any advice or suggested reading would be much appreciated.
Here's my advice: don't be afraid of the join.
Josh|||> Here's my advice: don't be afraid of the join.
Depends on what your objective is. Maximum flexibility or maximum
performance.
"JXStern" <JXSternChangeX2R@.gte.net> wrote in message
news:5dqgg3ho4gqhc31kbcg4m2u76snergnt9f@.4ax.com...
> On Fri, 05 Oct 2007 12:16:06 -0700, Chris
> <christopher.b.lewis@.gmail.com> wrote:
>>I have a database design question. I am dealing with a bunch of
>>standard content categories: people, addresses and companies. I don't
>>know whether I should have a table for each type of data and associate
>>addresses (via join tables) with people or companies or both; or
>>whether the companies table and the people tables should both include
>>address info. How far does one usually go to normalize these standard
>>types of data?
> The more time you spend with databases, the more you tend to factor
> things into 3NF or better as a default. Break out the addresses!
>
>>Sure, you could say that it depends on the specific business logic,
>>but I am curious if anyone out there has a way of normalizing this
>>type of data that has proven effective for most applications. I'm not
>>sure how our app will grow over time and therefore I want to
>>accommodate unforeseen requirements upfront without wasting untold
>>hours on far edge cases. Should I just bite the bullet and assume
>>we'll need a many-to-many relationship for each?
>>Any advice or suggested reading would be much appreciated.
> Here's my advice: don't be afraid of the join.
> Josh
>|||>> > Here's my advice: don't be afraid of the join.
>> Depends on what your objective is. Maximum flexibility or maximum
>> performance.
Except that one does not always have to sacrifice one to gain the other. And
a logical operation like join has little to do with either anyway.
Otherwise, anyone whose objective is maximum performance would be better of
avoiding joins altogether by having a single table :-)
--
Anith|||On Sun, 7 Oct 2007 19:52:32 -0500, "Anith Sen"
<anith@.bizdatasolutions.com> wrote:
>> > Here's my advice: don't be afraid of the join.
>> Depends on what your objective is. Maximum flexibility or maximum
>> performance.
>Except that one does not always have to sacrifice one to gain the other. And
>a logical operation like join has little to do with either anyway.
>Otherwise, anyone whose objective is maximum performance would be better of
>avoiding joins altogether by having a single table :-)
Well, by having a lot of redundant data pre-digested (joined and/or
aggregated) for common queries.
J.

Saturday, February 25, 2012

A question on ow to design some tables

Hi all,
I have a fairly tricky problem that I'm not sure how to approach.
I'm making a web application that manages drug trials. One of the
requirements of the system is if anyone makes changes to a field, the old
value and the new value need to be stored, along with the time of the change
and the reason for the change
The problem is I don't know how to support this for all the various fields
in all the various tables.
For example I have tables for storing basic patient details and then tables
for storing data on patient visits, patient screening data and so on.
Can anyone suggest how I could make a table or tables to store this audit
data for all the fields in all the tables? I'm not sure how to do it!
:-(
Thanks to anyone who can help
Simon
Hi Julie,
Thanks for your reply.
What I'm really stuck on is how to arrange the audit tables so that they can
store all sorts of information from the different types of data from all the
tables
Do you have any ideas along those lines?
Thanks again for your help!
Simon
|||What if you make duplicate tables and append "_archive" or similar to their
names, and use triggers to copy the original record in it's entirety to
these archive tables before inserting the new data into the main table?
"Simon Harvey" <simon.harvey@.the-web-works.co.uk> wrote in message
news:eexDr4VHEHA.2260@.TK2MSFTNGP09.phx.gbl...
> Hi Julie,
> Thanks for your reply.
> What I'm really stuck on is how to arrange the audit tables so that they
can
> store all sorts of information from the different types of data from all
the
> tables
> Do you have any ideas along those lines?
> Thanks again for your help!
> Simon
>
|||Hi Simon,
Keith has really answered the question. The best way I
have found how to do this is for every table you want to
audit, create an audit table.
In the example given to you two tables tblTesting is the
table the auditing is to take place, and tblTestAudit is
table where the changes will stored. You can cut paste and
run the code in Query Analyser and try it out if you want.
The example will capture every change made in the
tblTesting database and put the before and after values in
tblTestAudit.
What I actually showed you was quite basic, you can expand
it to show the name of the user who made the change, date
time of change, infact anything that can be programmed in.
So to recap.
1. The best way I have found is for each table you will to
audit create an audit table.
2. Cut and paste the demo, execute it in Query Analyser
and see what it does
3. Figure out what other things you need to change it.
Enjoy
J

>--Original Message--
>Hi Julie,
>Thanks for your reply.
>What I'm really stuck on is how to arrange the audit
tables so that they can
>store all sorts of information from the different types
of data from all the
>tables
>Do you have any ideas along those lines?
>Thanks again for your help!
>Simon
>
>.
>
|||Many thanks to both of you!
:-)
Simon

A question on ow to design some tables

Hi all,
I have a fairly tricky problem that I'm not sure how to approach.
I'm making a web application that manages drug trials. One of the
requirements of the system is if anyone makes changes to a field, the old
value and the new value need to be stored, along with the time of the change
and the reason for the change
The problem is I don't know how to support this for all the various fields
in all the various tables.
For example I have tables for storing basic patient details and then tables
for storing data on patient visits, patient screening data and so on.
Can anyone suggest how I could make a table or tables to store this audit
data for all the fields in all the tables? I'm not sure how to do it!
:-(
Thanks to anyone who can help
SimonHi Julie,
Thanks for your reply.
What I'm really stuck on is how to arrange the audit tables so that they can
store all sorts of information from the different types of data from all the
tables
Do you have any ideas along those lines?
Thanks again for your help!
Simon|||What if you make duplicate tables and append "_archive" or similar to their
names, and use triggers to copy the original record in it's entirety to
these archive tables before inserting the new data into the main table?
"Simon Harvey" <simon.harvey@.the-web-works.co.uk> wrote in message
news:eexDr4VHEHA.2260@.TK2MSFTNGP09.phx.gbl...
> Hi Julie,
> Thanks for your reply.
> What I'm really stuck on is how to arrange the audit tables so that they
can
> store all sorts of information from the different types of data from all
the
> tables
> Do you have any ideas along those lines?
> Thanks again for your help!
> Simon
>|||Hi Simon,
Keith has really answered the question. The best way I
have found how to do this is for every table you want to
audit, create an audit table.
In the example given to you two tables tblTesting is the
table the auditing is to take place, and tblTestAudit is
table where the changes will stored. You can cut paste and
run the code in Query Analyser and try it out if you want.
The example will capture every change made in the
tblTesting database and put the before and after values in
tblTestAudit.
What I actually showed you was quite basic, you can expand
it to show the name of the user who made the change, date
time of change, infact anything that can be programmed in.
So to recap.
1. The best way I have found is for each table you will to
audit create an audit table.
2. Cut and paste the demo, execute it in Query Analyser
and see what it does
3. Figure out what other things you need to change it.
Enjoy
J

>--Original Message--
>Hi Julie,
>Thanks for your reply.
>What I'm really stuck on is how to arrange the audit
tables so that they can
>store all sorts of information from the different types
of data from all the
>tables
>Do you have any ideas along those lines?
>Thanks again for your help!
>Simon
>
>.
>|||Many thanks to both of you!
:-)
Simon

A question on ow to design some tables

Hi all,
I have a fairly tricky problem that I'm not sure how to approach.
I'm making a web application that manages drug trials. One of the
requirements of the system is if anyone makes changes to a field, the old
value and the new value need to be stored, along with the time of the change
and the reason for the change
The problem is I don't know how to support this for all the various fields
in all the various tables.
For example I have tables for storing basic patient details and then tables
for storing data on patient visits, patient screening data and so on.
Can anyone suggest how I could make a table or tables to store this audit
data for all the fields in all the tables? I'm not sure how to do it!
:-(
Thanks to anyone who can help
SimonHi Simon,
There is an in built database utility called a Trigger,
these perform an automatic response for an INSERT, UPDATE
or DELETE.
You can access Triggers in EA by clicking on the 'Design'
of a table in EA, its the button next to primary key.
Anyway in the following example I have created three
triggers in a database table which stores the before and
after values in an audit table.
Give it a try and see if its what you want, you may also
want to read up about triggers on BOL.
J
CREATE TABLE [dbo].[tblTestAudit] (
[Type] [char] (6) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[ID] [int] NULL ,
[OldVal] [char] (20) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[NewVal] [char] (20) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[tblTesting] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[Testing] [char] (20) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblTesting] WITH NOCHECK ADD
CONSTRAINT [PK_tblTesting] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
GO
CREATE TRIGGER tk_INSERT ON [dbo].[tblTesting]
FOR INSERT
AS
DECLARE @.TKTYPE as char(6)
DECLARE @.ID as int
DECLARE @.NEW as char(20)
select @.ID = ID, @.NEW = Testing from inserted
insert into tblTestAudit (Type, ID, OldVal, NewVal) Values
('INSERT', @.ID, '', @.NEW)
GO
CREATE TRIGGER tk_DELETE ON [dbo].[tblTesting]
FOR DELETE
AS
DECLARE @.TKTYPE as char(6)
DECLARE @.ID as int
DECLARE @.OLD as char(20)
select @.ID = ID, @.OLD = Testing from deleted
insert into tblTestAudit (Type, ID, OldVal, NewVal) Values
('DELETE', @.ID, '@.OLD', '')
GO
CREATE TRIGGER tk_UPDATE ON [dbo].[tblTesting]
FOR UPDATE
AS
DECLARE @.TKTYPE as char(6)
DECLARE @.ID as int
DECLARE @.NEW as char(20)
DECLARE @.OLD as char(20)
select @.OLD = Testing from deleted
select @.ID = ID, @.NEW = Testing from inserted
insert into tblTestAudit (Type, ID, OldVal, NewVal) Values
('DELETE', @.ID, '@.OLD', '@.NEW')
>--Original Message--
>Hi all,
>I have a fairly tricky problem that I'm not sure how to
approach.
>I'm making a web application that manages drug trials.
One of the
>requirements of the system is if anyone makes changes to
a field, the old
>value and the new value need to be stored, along with the
time of the change
>and the reason for the change
>The problem is I don't know how to support this for all
the various fields
>in all the various tables.
>For example I have tables for storing basic patient
details and then tables
>for storing data on patient visits, patient screening
data and so on.
>Can anyone suggest how I could make a table or tables to
store this audit
>data for all the fields in all the tables? I'm not sure
how to do it!
>:-(
>Thanks to anyone who can help
>Simon
>
>.
>|||Hi Julie,
Thanks for your reply.
What I'm really stuck on is how to arrange the audit tables so that they can
store all sorts of information from the different types of data from all the
tables
Do you have any ideas along those lines?
Thanks again for your help!
Simon|||What if you make duplicate tables and append "_archive" or similar to their
names, and use triggers to copy the original record in it's entirety to
these archive tables before inserting the new data into the main table?
"Simon Harvey" <simon.harvey@.the-web-works.co.uk> wrote in message
news:eexDr4VHEHA.2260@.TK2MSFTNGP09.phx.gbl...
> Hi Julie,
> Thanks for your reply.
> What I'm really stuck on is how to arrange the audit tables so that they
can
> store all sorts of information from the different types of data from all
the
> tables
> Do you have any ideas along those lines?
> Thanks again for your help!
> Simon
>|||Hi Simon,
Keith has really answered the question. The best way I
have found how to do this is for every table you want to
audit, create an audit table.
In the example given to you two tables tblTesting is the
table the auditing is to take place, and tblTestAudit is
table where the changes will stored. You can cut paste and
run the code in Query Analyser and try it out if you want.
The example will capture every change made in the
tblTesting database and put the before and after values in
tblTestAudit.
What I actually showed you was quite basic, you can expand
it to show the name of the user who made the change, date
time of change, infact anything that can be programmed in.
So to recap.
1. The best way I have found is for each table you will to
audit create an audit table.
2. Cut and paste the demo, execute it in Query Analyser
and see what it does
3. Figure out what other things you need to change it.
Enjoy
J
>--Original Message--
>Hi Julie,
>Thanks for your reply.
>What I'm really stuck on is how to arrange the audit
tables so that they can
>store all sorts of information from the different types
of data from all the
>tables
>Do you have any ideas along those lines?
>Thanks again for your help!
>Simon
>
>.
>|||Many thanks to both of you!
:-)
Simon

A question on database design

Hi everyone,
I'm hoping someone could give me some advice on how to achieve the following.
I'm making a system that stores information on holiday homes. In particular
I need to store information on their bookings. When is a home occupied and
for how long.
I've considered making a Bookings table which would be somthing like:
ID
HomeID
StartDate
EndDate
What I can't see yet is how I'm going to query this table to find all properties
that are available for a given period.
What I want to be able to say is show me all homes that are available between
the 12th of april and the 27th of April.
Can anyone suggest how that query would work? Or is there perhaps a better
way to store this booking information?
Any advice and suggestions would be gratefully received.
Kindest Regards
Simon
> I've considered making a Bookings table which would be somthing like:
> ID
How about BookingID? ID is meaningless and can easily be taken out of
context.

> What I can't see yet is how I'm going to query this table to find all
> properties that are available for a given period.

> What I want to be able to say is show me all homes that are available
> between the 12th of april and the 27th of April.
-- untested, due to lack of DDL, sample data, desired results;
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND
(
b.StartDate BETWEEN @.startDate AND @.endDate
OR
b.EndDate BETWEEN @.startDate AND @.endDate
)
);
|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.
Don't you need a few more things in Bookings?
CREATE TABLE Bookings
(customer_id INTEGER NOT NULL
REFERENCES Customers(customer_id),
property_id INTEGER NOT NULL
REFERENCES Properties (property_id),
start_date DATETIME NOT NULL,
end_date DATETIME,
CHECK (start_date < end_date),
rental_rate DECIMAL (8,2) NOT NULL
CHECK (rental_rate > 0.00),
PRIMARY KEY (customer_id, property_id, start_date));
[vbcol=seagreen]
the 12th of April and the 27th of April. <<
I would build a Calendar table which is discussed in a lot of old
postings.
SELECT @.my_arrival, @.my_depart, P.property_id
FROM Properties AS P
WHERE NOT EXISTS
(SELECT *
FROM Bookings AS B,
Calendar AS C
WHERE C.cal_date
BETWEEN B.start_date AND B.end_date
AND B.property_id = P.property_id
AND cal_date BETWEEN @.my_arrival AND @.my_depart);
Untested.
(SELECT cal_date
FROM Calendar
WHERE cal_date BETWEEN @.my_arrival AND @.my_depart) AS X(cal_date)
|||You should consider recording dates for which a given unit is actually
available. One way is to create "fake" bookings for non-availability
dates - but that can get ugly.
|||On Tue, 17 Jan 2006 07:28:49 -0800, Simon Harvey wrote:
(snip)
>Can anyone suggest how that query would work? Or is there perhaps a better
>way to store this booking information?
Hi Simon,
Depending on your indexes, the query below might run faster than the
query Aaron suggests:
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND b.StartDate <= @.endDate
AND b.EndDate >= @.startDate
);
NOTE: I've set the follow-up to just the SQL Server groups. I can't help
with Access syntax anyway.
Hugo Kornelis, SQL Server MVP
|||Hi everyone
[vbcol=seagreen]
context.
Actually, the primary key in my tables is always ID, that way you never have
to think about it. I used to do it the other way, but then I got to thinking,
why call it BookingID? It's obviously a BookingID by virtue of the fact that
its the ID of the Booking table. I always fully qualify column names anyway
so I use Bookings.ID. I've heard some people say that doing this makes things
faster but I don't really care. I just do it for clarity and to avoid conflicts.
Of course if I was dealing with a foregin key in a table then I'd call it
BookingID because that would be implicitly helpful and quite necessary.
[vbcol=seagreen]
Declarative Referential Integrity, data types, etc. in your schema are. Sample
data is also a good idea, along with clear specifications. It is very hard
to debug code when you do not let us see it."
Well that would be difficult considering I don't have any DDL to offer. I
was asking a general queston on how to achieve an end goal. I suggested a
bookings table which was remarkably simple and existed only in my head. I
thought it was simple enough to be clear to those who saw the possible columns.
Thank you to everyone who has given some suggestions. I think I was pretty
much getting to the same conclusion as Aarons suggestion, but thats solidified
it in my mind.
Thanks again
Simon

A question on database design

Hi everyone,
I'm hoping someone could give me some advice on how to achieve the following
.
I'm making a system that stores information on holiday homes. In particular
I need to store information on their bookings. When is a home occupied and
for how long.
I've considered making a Bookings table which would be somthing like:
ID
HomeID
StartDate
EndDate
What I can't see yet is how I'm going to query this table to find all proper
ties
that are available for a given period.
What I want to be able to say is show me all homes that are available betwee
n
the 12th of april and the 27th of April.
Can anyone suggest how that query would work? Or is there perhaps a better
way to store this booking information?
Any advice and suggestions would be gratefully received.
Kindest Regards
Simon> I've considered making a Bookings table which would be somthing like:
> ID
How about BookingID? ID is meaningless and can easily be taken out of
context.

> What I can't see yet is how I'm going to query this table to find all
> properties that are available for a given period.

> What I want to be able to say is show me all homes that are available
> between the 12th of april and the 27th of April.
-- untested, due to lack of DDL, sample data, desired results;
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND
(
b.StartDate BETWEEN @.startDate AND @.endDate
OR
b.EndDate BETWEEN @.startDate AND @.endDate
)
);|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.
Don't you need a few more things in Bookings?
CREATE TABLE Bookings
(customer_id INTEGER NOT NULL
REFERENCES Customers(customer_id),
property_id INTEGER NOT NULL
REFERENCES Properties (property_id),
start_date DATETIME NOT NULL,
end_date DATETIME,
CHECK (start_date < end_date),
rental_rate DECIMAL (8,2) NOT NULL
CHECK (rental_rate > 0.00),
PRIMARY KEY (customer_id, property_id, start_date));
the 12th of April and the 27th of April. <<
I would build a Calendar table which is discussed in a lot of old
postings.
SELECT @.my_arrival, @.my_depart, P.property_id
FROM Properties AS P
WHERE NOT EXISTS
(SELECT *
FROM Bookings AS B,
Calendar AS C
WHERE C.cal_date
BETWEEN B.start_date AND B.end_date
AND B.property_id = P.property_id
AND cal_date BETWEEN @.my_arrival AND @.my_depart);
Untested.
(SELECT cal_date
FROM Calendar
WHERE cal_date BETWEEN @.my_arrival AND @.my_depart) AS X(cal_date)|||You should consider recording dates for which a given unit is actually
available. One way is to create "fake" bookings for non-availability
dates - but that can get ugly.|||On Tue, 17 Jan 2006 07:28:49 -0800, Simon Harvey wrote:
(snip)
>Can anyone suggest how that query would work? Or is there perhaps a better
>way to store this booking information?
Hi Simon,
Depending on your indexes, the query below might run faster than the
query Aaron suggests:
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND b.StartDate <= @.endDate
AND b.EndDate >= @.startDate
);
NOTE: I've set the follow-up to just the SQL Server groups. I can't help
with Access syntax anyway.
Hugo Kornelis, SQL Server MVP|||Hi everyone
context.
Actually, the primary key in my tables is always ID, that way you never have
to think about it. I used to do it the other way, but then I got to thinking
,
why call it BookingID? It's obviously a BookingID by virtue of the fact that
its the ID of the Booking table. I always fully qualify column names anyway
so I use Bookings.ID. I've heard some people say that doing this makes thing
s
faster but I don't really care. I just do it for clarity and to avoid confli
cts.
Of course if I was dealing with a foregin key in a table then I'd call it
BookingID because that would be implicitly helpful and quite necessary.
Declarative Referential Integrity, data types, etc. in your schema are. Samp
le
data is also a good idea, along with clear specifications. It is very hard
to debug code when you do not let us see it."
Well that would be difficult considering I don't have any DDL to offer. I
was asking a general queston on how to achieve an end goal. I suggested a
bookings table which was remarkably simple and existed only in my head. I
thought it was simple enough to be clear to those who saw the possible colum
ns.
Thank you to everyone who has given some suggestions. I think I was pretty
much getting to the same conclusion as Aarons suggestion, but thats solidifi
ed
it in my mind.
Thanks again
Simon

A question on database design

Hi everyone,
I'm hoping someone could give me some advice on how to achieve the following
.
I'm making a system that stores information on holiday homes. In particular
I need to store information on their bookings. When is a home occupied and
for how long.
I've considered making a Bookings table which would be somthing like:
ID
HomeID
StartDate
EndDate
What I can't see yet is how I'm going to query this table to find all proper
ties
that are available for a given period.
What I want to be able to say is show me all homes that are available betwee
n
the 12th of april and the 27th of April.
Can anyone suggest how that query would work? Or is there perhaps a better
way to store this booking information?
Any advice and suggestions would be gratefully received.
Kindest Regards
Simon> I've considered making a Bookings table which would be somthing like:
> ID
How about BookingID? ID is meaningless and can easily be taken out of
context.

> What I can't see yet is how I'm going to query this table to find all
> properties that are available for a given period.

> What I want to be able to say is show me all homes that are available
> between the 12th of april and the 27th of April.
-- untested, due to lack of DDL, sample data, desired results;
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND
(
b.StartDate BETWEEN @.startDate AND @.endDate
OR
b.EndDate BETWEEN @.startDate AND @.endDate
)
);|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.
Don't you need a few more things in Bookings?
CREATE TABLE Bookings
(customer_id INTEGER NOT NULL
REFERENCES Customers(customer_id),
property_id INTEGER NOT NULL
REFERENCES Properties (property_id),
start_date DATETIME NOT NULL,
end_date DATETIME,
CHECK (start_date < end_date),
rental_rate DECIMAL (8,2) NOT NULL
CHECK (rental_rate > 0.00),
PRIMARY KEY (customer_id, property_id, start_date));
[vbcol=seagreen]
the 12th of April and the 27th of April. <<
I would build a Calendar table which is discussed in a lot of old
postings.
SELECT @.my_arrival, @.my_depart, P.property_id
FROM Properties AS P
WHERE NOT EXISTS
(SELECT *
FROM Bookings AS B,
Calendar AS C
WHERE C.cal_date
BETWEEN B.start_date AND B.end_date
AND B.property_id = P.property_id
AND cal_date BETWEEN @.my_arrival AND @.my_depart);
Untested.
(SELECT cal_date
FROM Calendar
WHERE cal_date BETWEEN @.my_arrival AND @.my_depart) AS X(cal_date)|||You should consider recording dates for which a given unit is actually
available. One way is to create "fake" bookings for non-availability
dates - but that can get ugly.|||On Tue, 17 Jan 2006 07:28:49 -0800, Simon Harvey wrote:
(snip)
>Can anyone suggest how that query would work? Or is there perhaps a better
>way to store this booking information?
Hi Simon,
Depending on your indexes, the query below might run faster than the
query Aaron suggests:
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND b.StartDate <= @.endDate
AND b.EndDate >= @.startDate
);
NOTE: I've set the follow-up to just the SQL Server groups. I can't help
with Access syntax anyway.
Hugo Kornelis, SQL Server MVP|||Hi everyone
[vbcol=seagreen]
context.
Actually, the primary key in my tables is always ID, that way you never have
to think about it. I used to do it the other way, but then I got to thinking
,
why call it BookingID? It's obviously a BookingID by virtue of the fact that
its the ID of the Booking table. I always fully qualify column names anyway
so I use Bookings.ID. I've heard some people say that doing this makes thing
s
faster but I don't really care. I just do it for clarity and to avoid confli
cts.
Of course if I was dealing with a foregin key in a table then I'd call it
BookingID because that would be implicitly helpful and quite necessary.
[vbcol=seagreen]
Declarative Referential Integrity, data types, etc. in your schema are. Samp
le
data is also a good idea, along with clear specifications. It is very hard
to debug code when you do not let us see it."
Well that would be difficult considering I don't have any DDL to offer. I
was asking a general queston on how to achieve an end goal. I suggested a
bookings table which was remarkably simple and existed only in my head. I
thought it was simple enough to be clear to those who saw the possible colum
ns.
Thank you to everyone who has given some suggestions. I think I was pretty
much getting to the same conclusion as Aarons suggestion, but thats solidifi
ed
it in my mind.
Thanks again
Simon

A question on database design

Hi everyone,
I'm hoping someone could give me some advice on how to achieve the following.
I'm making a system that stores information on holiday homes. In particular
I need to store information on their bookings. When is a home occupied and
for how long.
I've considered making a Bookings table which would be somthing like:
ID
HomeID
StartDate
EndDate
What I can't see yet is how I'm going to query this table to find all properties
that are available for a given period.
What I want to be able to say is show me all homes that are available between
the 12th of april and the 27th of April.
Can anyone suggest how that query would work? Or is there perhaps a better
way to store this booking information?
Any advice and suggestions would be gratefully received.
Kindest Regards
Simon> I've considered making a Bookings table which would be somthing like:
> ID
How about BookingID? ID is meaningless and can easily be taken out of
context.
> What I can't see yet is how I'm going to query this table to find all
> properties that are available for a given period.
> What I want to be able to say is show me all homes that are available
> between the 12th of april and the 27th of April.
-- untested, due to lack of DDL, sample data, desired results;
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND
(
b.StartDate BETWEEN @.startDate AND @.endDate
OR
b.EndDate BETWEEN @.startDate AND @.endDate
)
);|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.
Don't you need a few more things in Bookings?
CREATE TABLE Bookings
(customer_id INTEGER NOT NULL
REFERENCES Customers(customer_id),
property_id INTEGER NOT NULL
REFERENCES Properties (property_id),
start_date DATETIME NOT NULL,
end_date DATETIME,
CHECK (start_date < end_date),
rental_rate DECIMAL (8,2) NOT NULL
CHECK (rental_rate > 0.00),
PRIMARY KEY (customer_id, property_id, start_date));
>> What I want to be able to say is show me all homes that are available between
the 12th of April and the 27th of April. <<
I would build a Calendar table which is discussed in a lot of old
postings.
SELECT @.my_arrival, @.my_depart, P.property_id
FROM Properties AS P
WHERE NOT EXISTS
(SELECT *
FROM Bookings AS B,
Calendar AS C
WHERE C.cal_date
BETWEEN B.start_date AND B.end_date
AND B.property_id = P.property_id
AND cal_date BETWEEN @.my_arrival AND @.my_depart);
Untested.
(SELECT cal_date
FROM Calendar
WHERE cal_date BETWEEN @.my_arrival AND @.my_depart) AS X(cal_date)|||You should consider recording dates for which a given unit is actually
available. One way is to create "fake" bookings for non-availability
dates - but that can get ugly.|||On Tue, 17 Jan 2006 07:28:49 -0800, Simon Harvey wrote:
(snip)
>Can anyone suggest how that query would work? Or is there perhaps a better
>way to store this booking information?
Hi Simon,
Depending on your indexes, the query below might run faster than the
query Aaron suggests:
DECLARE @.startDate SMALLDATETIME, @.endDate SMALLDATETIME;
SELECT @.startDate = '20060412', @.endDate = '20060427';
SELECT HomeID, Description
FROM dbo.Homes h
WHERE NOT EXISTS
(
SELECT 1
FROM dbo.Bookings b
WHERE b.HomeID = h.HomeID
AND b.StartDate <= @.endDate
AND b.EndDate >= @.startDate
);
NOTE: I've set the follow-up to just the SQL Server groups. I can't help
with Access syntax anyway.
--
Hugo Kornelis, SQL Server MVP

A question of design

Hi,
My apologies if this isn't strictly the right group but you've always been
very helpful in the past so...
I was wondering if there were any best practices with regards to the
following scenario:
Given a simple FK relationship (employees table to transaction table for
example), is there a best method for catering for employee information that
wouldn't appear in the employees table - for cample contractors. I.e. given
a transaction which included salaried employees (who would appear in the
employee table as designed) and 3rd party contractors who wouldn't, I'm not
certain as the best way to handle this. I can't simply include a
"Contractor" employee as each employee is unique to a transaction.
I'm thinking of "breaking" the FK relationship so that in the transaction
table, for a contractor a standard value could be used ("C1", "C2", "C3",
"Cn"), for an employee their ID is entered as usual and enforcing RI through
sprocs and triggers. However I'm concerned about whether this approach is a
"valid" one.
I hope I've managed to convey this clearly enough, any advice, assistance or
replies in general are gratefully recieved.
Kind regards
Chris.In my opinion you should have separate table for employees and separate for
contractors. then you will not be forced to 'tweak' relationships. in
general, employees and contractors seem to be separate entity types.
Peter|||"Rogas69" <rogas69@.no_spamers.o2.ie> wrote in message
news:ej4Vs81RGHA.5656@.TK2MSFTNGP11.phx.gbl...
> In my opinion you should have separate table for employees and separate
> for contractors. then you will not be forced to 'tweak' relationships. in
> general, employees and contractors seem to be separate entity types.
> Peter
>
Peter,
Thanks for your view. After looking at this, I've pretty much came to the
same conclusion, in that the Transaction table will reference an "Employee"
table and a "Contractor" table - both of which allow zero / one to many
relationships. For querying, I'm imagining a COALESCE between the two sets
of data...
Again, your thoughts on this (specifically using the COALESCE command to
combine the data when querying) would be greatly appreciated.
Thanks again
Chris.|||Chris Strug wrote:
> Hi,
> My apologies if this isn't strictly the right group but you've always been
> very helpful in the past so...
> I was wondering if there were any best practices with regards to the
> following scenario:
> Given a simple FK relationship (employees table to transaction table for
> example), is there a best method for catering for employee information tha
t
> wouldn't appear in the employees table - for cample contractors. I.e. give
n
> a transaction which included salaried employees (who would appear in the
> employee table as designed) and 3rd party contractors who wouldn't, I'm no
t
> certain as the best way to handle this. I can't simply include a
> "Contractor" employee as each employee is unique to a transaction.
> I'm thinking of "breaking" the FK relationship so that in the transaction
> table, for a contractor a standard value could be used ("C1", "C2", "C3",
> "Cn"), for an employee their ID is entered as usual and enforcing RI throu
gh
> sprocs and triggers. However I'm concerned about whether this approach is
a
> "valid" one.
> I hope I've managed to convey this clearly enough, any advice, assistance
or
> replies in general are gratefully recieved.
> Kind regards
> Chris.
If employee id is optional then you can put it in another table and
only populate it when relevant:
CREATE TABLE employee_transactions
(trans_id INTEGER NOT NULL PRIMARY KEY
REFERENCES transactions (trans_id),
emp_id INTEGER NOT NULL
REFERENCES employees (emp_id));
I'm not clear whether or how you want to track contractor ids however.
Posting your existing DDL and sample data might help make it clearer.
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/ms130214(en-US,SQL.90).aspx
--|||Please send some sample data and resired result then :)
Peter

Thursday, February 16, 2012

a player team tables design?

i am a beginner of database design, could anyone please help me to
figure out how to make these two tables work.

1) a "players" table, with columns "name", "age"
2) a "teams" table, which can have one OR two player(s)
a team also has a column "level", which may have values "A", "B",
or "C"

how do you build the "teams" table (the critical question is "do i
need to create two fields" for the maximum two possible players?")

how do you use one query to display the information with the following
columns:
"name", "age", "levelA", "levelB", "levelC" (the later three columns
are integer type, showing how many teams with coresponding level this
player is in).

now suppose i don't have any access to sql server, i save the data
into xml, and load it into a dataset. how could you do the selection
within the dataset? or ahead of that, how do you specify the relations
between "players" and "teams".

the following is the schema file i am trying to make (I still don't
know if i need to specified the primary key... and how to build
relation between them):
<code>
<?xml version="1.0" ?>
<xs:schema id="AllTables" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="AllTables" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Players">
<xs:complexType>
<xs:sequence>
<xs:element name="PlayerID" msdata:AutoIncrement="true"
type="xs:int" minOccurs="0" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="Age" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Teams">
<xs:complexType>
<xs:sequence>
<xs:element name="TeamID" msdata:AutoIncrement="true"
type="xs:int" minOccurs="0" />
<xs:element name="Level" type="xs:string" minOccurs="0" />
<xs:element name="Player1" type="xs:int" minOccurs="0" />
<xs:element name="Player2" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</code>In SQL it might be something like this to start with. Start reading about
normalization, relational theory, and table driven applications.

CREATE TABLE Team
( TeamId INTEGER NOT NULL PRIMARY KEY
, TeamName VARCHAR(40) NOT NULL
, TeamLevel CHAR(1) NOT NULL CHECK (TeamLevel IN ('A', 'B', 'C'))
)

CREATE TABLE Player
( PlayerId INTEGER NOT NULL PRIMARY KEY
, PlayerName VARCHAR(40) NOT NULL
, TeamId INTEGER NOT NULL FOREIGN KEY REFERENCES Team(TeamId)
)

"Alan Zhong" <alanchinese@.yahoo.com> wrote in message
news:b09c98a8.0408260048.79651f10@.posting.google.c om...
>i am a beginner of database design, could anyone please help me to
> figure out how to make these two tables work.
> 1) a "players" table, with columns "name", "age"
> 2) a "teams" table, which can have one OR two player(s)
> a team also has a column "level", which may have values "A", "B",
> or "C"
> how do you build the "teams" table (the critical question is "do i
> need to create two fields" for the maximum two possible players?")
> how do you use one query to display the information with the following
> columns:
> "name", "age", "levelA", "levelB", "levelC" (the later three columns
> are integer type, showing how many teams with coresponding level this
> player is in).
> now suppose i don't have any access to sql server, i save the data
> into xml, and load it into a dataset. how could you do the selection
> within the dataset? or ahead of that, how do you specify the relations
> between "players" and "teams".
>
> the following is the schema file i am trying to make (I still don't
> know if i need to specified the primary key... and how to build
> relation between them):
> <code>
> <?xml version="1.0" ?>
> <xs:schema id="AllTables" xmlns=""
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
> <xs:element name="AllTables" msdata:IsDataSet="true">
> <xs:complexType>
> <xs:choice maxOccurs="unbounded">
> <xs:element name="Players">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="PlayerID" msdata:AutoIncrement="true"
> type="xs:int" minOccurs="0" />
> <xs:element name="Name" type="xs:string" minOccurs="0" />
> <xs:element name="Age" type="xs:int" minOccurs="0" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="Teams">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="TeamID" msdata:AutoIncrement="true"
> type="xs:int" minOccurs="0" />
> <xs:element name="Level" type="xs:string" minOccurs="0" />
> <xs:element name="Player1" type="xs:int" minOccurs="0" />
> <xs:element name="Player2" type="xs:int" minOccurs="0" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:choice>
> </xs:complexType>
> </xs:element>
> </xs:schema>
> </code|||And this would be one way to express the query that you're looking for.
Feel free to add age to schema and query.

SELECT PlayerName
, (SELECT COUNT(*) FROM Team WHERE TeamId = Player.TeamId AND TeamLevel =
'A') As LevelA
, (SELECT COUNT(*) FROM Team WHERE TeamId = Player.TeamId AND TeamLevel =
'B') As LevelB
, (SELECT COUNT(*) FROM Team WHERE TeamId = Player.TeamId AND TeamLevel =
'C') As LevelC
FROM Player

"Larry S" <nospam@.bugus.zzz> wrote in message
news:M17Yc.107934$TI1.103116@.attbi_s52...
> In SQL it might be something like this to start with. Start reading about
> normalization, relational theory, and table driven applications.
> CREATE TABLE Team
> ( TeamId INTEGER NOT NULL PRIMARY KEY
> , TeamName VARCHAR(40) NOT NULL
> , TeamLevel CHAR(1) NOT NULL CHECK (TeamLevel IN ('A', 'B', 'C'))
> )
> CREATE TABLE Player
> ( PlayerId INTEGER NOT NULL PRIMARY KEY
> , PlayerName VARCHAR(40) NOT NULL
> , TeamId INTEGER NOT NULL FOREIGN KEY REFERENCES Team(TeamId)
> )
> "Alan Zhong" <alanchinese@.yahoo.com> wrote in message
> news:b09c98a8.0408260048.79651f10@.posting.google.c om...
>>i am a beginner of database design, could anyone please help me to
>> figure out how to make these two tables work.
>>
>> 1) a "players" table, with columns "name", "age"
>> 2) a "teams" table, which can have one OR two player(s)
>> a team also has a column "level", which may have values "A", "B",
>> or "C"
>>
>> how do you build the "teams" table (the critical question is "do i
>> need to create two fields" for the maximum two possible players?")
>>
>> how do you use one query to display the information with the following
>> columns:
>> "name", "age", "levelA", "levelB", "levelC" (the later three columns
>> are integer type, showing how many teams with coresponding level this
>> player is in).
>>
>> now suppose i don't have any access to sql server, i save the data
>> into xml, and load it into a dataset. how could you do the selection
>> within the dataset? or ahead of that, how do you specify the relations
>> between "players" and "teams".
>>
>>
>> the following is the schema file i am trying to make (I still don't
>> know if i need to specified the primary key... and how to build
>> relation between them):
>> <code>
>> <?xml version="1.0" ?>
>> <xs:schema id="AllTables" xmlns=""
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
>> <xs:element name="AllTables" msdata:IsDataSet="true">
>> <xs:complexType>
>> <xs:choice maxOccurs="unbounded">
>> <xs:element name="Players">
>> <xs:complexType>
>> <xs:sequence>
>> <xs:element name="PlayerID" msdata:AutoIncrement="true"
>> type="xs:int" minOccurs="0" />
>> <xs:element name="Name" type="xs:string" minOccurs="0" />
>> <xs:element name="Age" type="xs:int" minOccurs="0" />
>> </xs:sequence>
>> </xs:complexType>
>> </xs:element>
>> <xs:element name="Teams">
>> <xs:complexType>
>> <xs:sequence>
>> <xs:element name="TeamID" msdata:AutoIncrement="true"
>> type="xs:int" minOccurs="0" />
>> <xs:element name="Level" type="xs:string" minOccurs="0" />
>> <xs:element name="Player1" type="xs:int" minOccurs="0" />
>> <xs:element name="Player2" type="xs:int" minOccurs="0" />
>> </xs:sequence>
>> </xs:complexType>
>> </xs:element>
>> </xs:choice>
>> </xs:complexType>
>> </xs:element>
>> </xs:schema>
>> </code>

Saturday, February 11, 2012

A littel help with table design....

Hi all,

I have a fairly tricky problem that I'm not sure how to approach.

I'm making a web application that manages drug trials. One of the requirements of the system is if anyone makes changes to a field, the old value and the new value need to be stored, along with the time of the change and the reason for the change

The problem is I don't know how to support this for all the various fields in all the various tables.

For example I have tables for storing basic patient details and then tables for storing data on patient visits, patient screening data and so on.

Can anyone suggest how I could make a table or tables to store this audit data for all the fields in all the tables? I'm not sure how to do it!

:-(

Thanks to anyone who can help

SimonPersonally I'd do that logic in the objects rather than the DB. But if you want to use the DB then you need to create an Audit Table(s). Then use a trigger to write the values and a timestamp into the Autit table whenever the value changes.|||I need to do the similar thing.
I created second database as the log for the main one. It has all the table as the main one, and with additional fields to save userId, updata type, update date/time, etc.
Trigers are added to the main tables to insert old value into log database.
I appreciate it if anybody in this forum has better idea.

A lil help with DB design

I have a table to store members. For each member, I have flags like manager, verified, etc. How should I be storing the flags? As individual columns in the same table and using bit datatype or creating a new table called MemberStatus and creating 1 row for each flag?

Thanx in advance.

Premal.One table.|||no flags, no bit data

just more to interprete|||Option 1. Flags, bits.
1 = true, 0 = false. Not much to interpret.|||1 = true, 0 = false, Null = unknown ;)|||1 = true
0 = false
6 = not sure
9 = not applicable
NULL = unknown|||10 = drop dead gorgeous.|||7 = very fluffy.

-PatP|||to properly account for shades of gray, you should use a decimal.

.983 = high degree of truthiness
.015 = minor fib, won't hurt anyone|||"truthiness" heh

somebody is a big fan of TheDailyWTF

:)|||nah, i got it from Colbert. He invented that word.|||1 = true, 0 = false, Null = unknown ;)

Null does not mean unknown, it means the absence of any value, or non existence|||ah, i see, thanks brett

but ontologically speaking, "absence of any value, or non existence" includes unknown

it also includes not applicable, out of range, optional, forgot, maybe, and WTF!|||ah, i see, thanks brett

but ontologically speaking, "absence of any value, or non existence" includes unknown

it also includes not applicable, out of range, optional, forgot, maybe, and WTF!

Ummm no, unkown mean there's a quanity, but who knows.

Null means there's not even the understanding of any quantity

And I like the words you keep throwing out there

But shouldn't it be anti-ontologically

http://www.allwords.com/word-ontologically.html|||Ooh! NULL FIGHT! NULL FIGHT!|||Is that where you throw null pointer exceptions?

Sorry. Couldn't resist.|||Null fights usually turn out to be "Much Ado About Nothing".|||Ooh! NULL FIGHT! NULL FIGHT!

LOL

This message is too short

Thursday, February 9, 2012

A good Database Modelling Tool for Sql Server 2005

Hello i am looking for a good database modelling tool in order to design an
sql server database.
I have recently come across with DBDesigner 4. Can you suggest me a better
alternative?
Hello,
Go for microsoft Visio. Download a trial version from below URL:-
http://office.microsoft.com/en-us/visio/default.aspx
Thanks
Hari
"WoodenSWord" <WoodenSWord@.discussions.microsoft.com> wrote in message
news:2BE42E3C-457B-47F4-9B48-5909C70BF5FB@.microsoft.com...
> Hello i am looking for a good database modelling tool in order to design
> an
> sql server database.
> I have recently come across with DBDesigner 4. Can you suggest me a better
> alternative?
|||If you can persuade your company to fork out the cash, I'd recommend ERWIN :
http://www3.ca.com/solutions/Product.aspx?ID=260
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
|||I use Erwin but it is really expensive for most people. ER/Studio from
Embarcadero is also very good and much cheaper -
http://www.embarcadero.com/products/erstudio/index.html.
Roman
"WoodenSWord" wrote:

> Hello i am looking for a good database modelling tool in order to design an
> sql server database.
> I have recently come across with DBDesigner 4. Can you suggest me a better
> alternative?
|||We can 2nd that. We're a small agency and find er-studio almost
indespensible.
The developers are always after me for a new 'database map' ...
It's helpful to have a large format plotter around if you're going to be
creating systems with hundreds of tables and relations. Or current just
barely readable er-studio map for our water rights system measures roughly 3
x 4 feet.
Barry
in Oregon
"Roman Rehak" <RomanRehak@.discussions.microsoft.com> wrote in message
news:B79EFCE6-677E-4AD9-88A8-1579587F15BD@.microsoft.com...[vbcol=seagreen]
> I use Erwin but it is really expensive for most people. ER/Studio from
> Embarcadero is also very good and much cheaper -
> http://www.embarcadero.com/products/erstudio/index.html.
> Roman
> "WoodenSWord" wrote: