Showing posts with label type. Show all posts
Showing posts with label type. Show all posts

Monday, March 26, 2012

Help with sp_lock output

I am trying to figure out something in the dump of my sp_lock output
(sql server 2000)
spid Db Objectid IndId Type
Resource Mode Status
373 QADB 0 0 PAG
1:204097 S WAIT
What does an object id = 0 mean? i thought this always show the id of
an actual tableHi Derek,
The output you provided means that a shared lock is held on a page, not on a
table, hence the 0 value for objectid. Resource column states that the lock
is held on file id 1 page number 204097.
To easily work with locks and/or deadlocks, I suggest you try out the tool
called SQL Deadlock Detector. It monitors your database for locks and
deadlocks and
provides complete information on captured events. It tells you everything
you need to know (locked objects, blocked statements, blocking statements,
etc.) to solve your blocking/deadlock problems. The great thing about this
tool is it's event diagram which makes it exremely easy to see what exactly
is going on.
You can download it from here:
http://lakesidesql.com/downloads/DLD2/2_0_2007_809/DeadlockDetector2_Setup_08-09-2007.zip.
I've been using it for quite a while now (I purchased it) and find it very
handy and useful.
HTH.
"Derek" <gepetto_2000@.yahoo.com> wrote in message
news:1187376178.875402.209170@.d55g2000hsg.googlegroups.com...
>I am trying to figure out something in the dump of my sp_lock output
> (sql server 2000)
> spid Db Objectid IndId Type
> Resource Mode Status
> 373 QADB 0 0 PAG
> 1:204097 S WAIT
> What does an object id = 0 mean? i thought this always show the id of
> an actual table
>

Help with sorting strings...

I'm trying to search a database and get a list of results of
the latest values which are of type 'STRING'. How would I do it?

For instance, I've got a dataset like the one below.

Col 1 Col 2 Col 3
---------------
Dog Blue 11a
Dog Blue 11b
Cat Blue 14
Cat Red 21a
Cat Red 21b
Fish Yellow 31
Shark Black 12a
Shark Purple 21

I only want it to return the ones with the highest 'Col 3' value, so it returns something like.

Col 1 Col 2 Col 3
----------------
Dog Blue 11b
Cat Red 21b
Fish Yellow 31
Shark Purple 21

I've tried something like this:

SELECT
table.col1,
table.col2,
table.col3
FROM
table
WHERE
1 > (
SELECT
COUNT(DISTINCT table.col3)
FROM
table tab
WHERE
tab.col3 > table.col3
)

However I get the ERR: An aggregate may not appear in the WHERE clause
unless it is in a subquery contained in a HAVING clause or select
list, and the column being aggregated is an outer reference.I don't what your backend database is but this should help.

SELECT t.col1
, t.col2
, t.col3
FROM tablex t
, (SELECT tablex.col1
, max (tablex.col3) col3
FROM tablex
group by col1) g
WHERE t.col1 = g.col1
AND t.col3 = g.col3
;

or using ANSI joins

SELECT t.col1
, t.col2
, t.col3
FROM tablex t
JOIN (SELECT tablex.col1
, max (tablex.col3) col3
FROM tablex
group by col1) g
ON t.col1 = g.col1
AND t.col3 = g.col3
;|||Thanks for your help gannet.

Friday, March 23, 2012

Help with Security!

I have a web application for which I am required to authenticate users at the database level (no generic or application type logins permitted). I am not permitted to use Active Directory because we do not have AD installed. We chose to use standard SQL accounts. I have two groups of users:

1. Normal users
2. Super Users (can do everything a normal user can do, plus can add/delete/modify user accounts)

When a Super User is created, they are added to three fixed roles Security Administrator (Server Role) and db_accessadmin and db_securityadmin (Database Roles).

A normal user is assigned to some custom roles that we created, but is not assigned to any fixed roles (database or server) other than the default Public role.

The problem comes when a Super User attempt to add another Super user. The process fails because the Super user does not have sufficient privileges to run sp_addrolemember. The following two statements fail because of permissions:

sp_addrolemember 'db_securityadmin', N'mySuperUser'
sp_addrolemember 'db_accessadmin', N'mySuperUser'

Additional research indicates that I am required to be a member of the SysAdmin fixed role of the db_Owner role in order to have access to sp_addrolemember.

Does anyone have any suggestions for a workaround? This is pretty frustrating. I am unwilling to let my Super Users have sysadmin or db_owner rights. These grant far more access than is needed. I just want my super users to be able to add and administer normal user accounts and other Super User accounts.

Thanks,

Hugh ScottI think you are using SQL2K, if so how about using Application roles? I have not done this before but it might be worth checking out. Look up Application Roles in BOL.

My theory is that you could setup an application role with dbo authority. When you need to create a superuser you would make an additional connection to the db using an application role, create the super user and then drop the connection.|||Ding!

You are correct. I should have stated that we were using SQL 2K. I like your idea and I will give it a shot.

Thanks!

Hugh

Originally posted by Paul Young
I think you are using SQL2K, if so how about using Application roles? I have not done this before but it might be worth checking out. Look up Application Roles in BOL.

My theory is that you could setup an application role with dbo authority. When you need to create a superuser you would make an additional connection to the db using an application role, create the super user and then drop the connection.sql

Wednesday, March 21, 2012

Help with reformatting xml

This is a simplistic example of what I’m trying to achieve;
I have some XML stored in a table (in a column of type xml):
<root>
<node id="1" somevalue="0" />
<node id="2" somevalue="1" />
<node id="3" somevalue="5" />
<node id="4" somevalue="7" />
</root>
And I want to generate new xml as follows:
<report>
<somevalue>13</somevalue>
</report>
Where 13 is the total value of all somevalue attributes.
I’ve been looking at the query() and nodes() methods and cannot quite do
what I want to do although I feel it might be possible. Currently I’m simply
selecting the xml and letting my client application do the formatting,
however I feel that this might cause some performance issues on large blobs
of xml data.
Is there a better way to do this?
Many thanks in advance for any help with this.
Julia Beresford.
Something like this?
DECLARE @.doc XML;
SELECT @.doc = N'<root>
<node id="1" somevalue="0" />
<node id="2" somevalue="1" />
<node id="3" somevalue="5" />
<node id="4" somevalue="7" />
</root>';
SELECT @.doc.query('<report>
<somevalue>
{ fn:sum(/root/node/@.somevalue) }
</somevalue>
</report>');
"Julia Beresford" <JuliaBeresford@.discussions.microsoft.com> wrote in
message news:5A5E83A9-F098-454D-80FA-FA212A3B15E8@.microsoft.com...
> This is a simplistic example of what I'm trying to achieve;
> I have some XML stored in a table (in a column of type xml):
> <root>
> <node id="1" somevalue="0" />
> <node id="2" somevalue="1" />
> <node id="3" somevalue="5" />
> <node id="4" somevalue="7" />
> </root>
> And I want to generate new xml as follows:
> <report>
> <somevalue>13</somevalue>
> </report>
> Where 13 is the total value of all somevalue attributes.
> I've been looking at the query() and nodes() methods and cannot quite do
> what I want to do although I feel it might be possible. Currently I'm
> simply
> selecting the xml and letting my client application do the formatting,
> however I feel that this might cause some performance issues on large
> blobs
> of xml data.
> Is there a better way to do this?
> Many thanks in advance for any help with this.
> Julia Beresford.
>

Help with reformatting xml

This is a simplistic example of what I’m trying to achieve;
I have some XML stored in a table (in a column of type xml):
<root>
<node id="1" somevalue="0" />
<node id="2" somevalue="1" />
<node id="3" somevalue="5" />
<node id="4" somevalue="7" />
</root>
And I want to generate new xml as follows:
<report>
<somevalue>13</somevalue>
</report>
Where 13 is the total value of all somevalue attributes.
I’ve been looking at the query() and nodes() methods and cannot quite do
what I want to do although I feel it might be possible. Currently I’m sim
ply
selecting the xml and letting my client application do the formatting,
however I feel that this might cause some performance issues on large blobs
of xml data.
Is there a better way to do this?
Many thanks in advance for any help with this.
Julia Beresford.Something like this?
DECLARE @.doc XML;
SELECT @.doc = N'<root>
<node id="1" somevalue="0" />
<node id="2" somevalue="1" />
<node id="3" somevalue="5" />
<node id="4" somevalue="7" />
</root>';
SELECT @.doc.query('<report>
<somevalue>
{ fn:sum(/root/node/@.somevalue) }
</somevalue>
</report>');
"Julia Beresford" <JuliaBeresford@.discussions.microsoft.com> wrote in
message news:5A5E83A9-F098-454D-80FA-FA212A3B15E8@.microsoft.com...
> This is a simplistic example of what I'm trying to achieve;
> I have some XML stored in a table (in a column of type xml):
> <root>
> <node id="1" somevalue="0" />
> <node id="2" somevalue="1" />
> <node id="3" somevalue="5" />
> <node id="4" somevalue="7" />
> </root>
> And I want to generate new xml as follows:
> <report>
> <somevalue>13</somevalue>
> </report>
> Where 13 is the total value of all somevalue attributes.
> I've been looking at the query() and nodes() methods and cannot quite do
> what I want to do although I feel it might be possible. Currently I'm
> simply
> selecting the xml and letting my client application do the formatting,
> however I feel that this might cause some performance issues on large
> blobs
> of xml data.
> Is there a better way to do this?
> Many thanks in advance for any help with this.
> Julia Beresford.
>

Monday, March 19, 2012

Help with Query ?

have two tables with the following strcuture :

Test Type
ID
GroupID
Type

Type Group
GroupID
Description

Now type group has lot of data in it, I want only
GroupID which has specific name
so I did....

SELECT * FROM
TypeGroup tg
WHERE tg.Description = 'Test'
OR tg.Description = 'Test1'

Now this gives me two groupID's so far its fine....

Now based on the groupID's I need to get all the types
from Test Type Table and I did something like this :

SELECT Type
FROM TypeGroup tg, TestType tt
WHERE tg.Description = 'Test'
OR tg.Description = 'Test1'
AND tg.GroupID = tt.GroupID

The above where its not happy, How can I perform to get
the desired results :

The result what I'm getting now is everything and some
repetition from TestType table...

Sample Data :

Type Group Table
1, Test
2, Test1
3, Test2
4, Test4
5, Test10

Test Type Table
1, 1, Something
2,1, Something else
3,1, Something different
4, 2, Very Different
5,3,Testing is good
6,3, Do More Testing<br. 7,4,Yield Better Results>
8,5, The better the results, better it is

From the Query I'm looking for is
Something,Somethng else, Something different, Very Different

Thanks a lot for the help.

First, you are using the 'old form' of JOINs. A JOIN should be in the new form for reliability. If I understand your question correctly, this may work for you:

Code Snippet


SET NOCOUNT ON


DECLARE @.TypeGroup table
( TypeGroupID int IDENTITY,
TypeDescrip varchar(20)
)


INSERT INTO @.TypeGroup VALUES ( 'Test' )
INSERT INTO @.TypeGroup VALUES ( 'Test1' )
INSERT INTO @.TypeGroup VALUES ( 'Test2' )
INSERT INTO @.TypeGroup VALUES ( 'Test4' )
INSERT INTO @.TypeGroup VALUES ( 'Test10' )


DECLARE @.TestType table
( TestTypeID int IDENTITY,
TypeGroupID int,
TestDescript varchar(50)
)


INSERT INTO @.TestType VALUES ( 1, 'Something' )
INSERT INTO @.TestType VALUES ( 1, 'Something else' )
INSERT INTO @.TestType VALUES ( 1, 'Something different' )
INSERT INTO @.TestType VALUES ( 2, 'Very Different' )
INSERT INTO @.TestType VALUES ( 2, 'Very Different' )
INSERT INTO @.TestType VALUES ( 3, 'Testing is good' )
INSERT INTO @.TestType VALUES ( 4, 'Testing is good' )
INSERT INTO @.TestType VALUES ( 3, 'Do More Testing' )
INSERT INTO @.TestType VALUES ( 4, 'Yield Better Results' )
INSERT INTO @.TestType VALUES ( 5, 'The better the results, better it is' )


SELECT DISTINCT tt.TestDescript
FROM @.TypeGroup tg
JOIN @.TestType tt
ON tg.TypeGroupID = tt.TypeGroupID
WHERE ( tg.TypeDescrip = 'Test'
OR tg.TypeDescrip = 'Test1'
)

Friday, February 24, 2012

Help with Many-to-Many-to-Many Problem

I am having a problem creating a many-to-many-to-many type relationship. It
works fine, but when I create a view to query it and test it, it does not
generate the results I expected.
Below if the DDL for the tables and the SQL for the view.
Any help would be most appreciated.
Many thanks in advance.
Regards
Keith
DIAGRAM 5: SYS_Relationship_Individuals_Courses
(http://www.step-online.org.uk/diagram5.png)
This is the relationship I am having a problem with. Each individual can
attend many courses. I have tried to model this by creating this diagram.
It has the following tables in it. SYS_Individual (to show individuals).
To show courses (which already have a many-to-many relationship
(http://www.step-online.org.uk/diagram2.png), I added all the same tables as
in diagram 2 - SYS_Courses, SYS_Courses_Venues, SYS_Courses_TimeTable,
SYS_Courses_Tutors (joined using SYS_Xref_Join_Courses). Now as each
individual could attend many courses, I assumed that the correct way to
model this would be by creating another many-to-many between the
SYS_Individual table and the SYS_Xref_Join_Courses by using a new join table
(SYS_Xref_Join_Ind_Courses).
I tried to check this works using a view (SYS_Individual_Courses_List) -
VIEW 5 below.
The problem is that no matter how many entries I put in the
SYS_Xref_Join_Ind_Courses, the test view (VIEW 5 below), only ever shows one
record. While playing around with the view, I got it to show all the
entries, but they were duplicated 4 times each! I can't remember how I did
this now either.
Now for the DDL for the tables:
CREATE TABLE [do].[SYS_Individual] (
[IND_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[IND_Date_Entered] [datetime] NOT NULL ,
[IND_Date_on_Project] [datetime] NULL ,
[IND_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Post_Code] [varchar] (10) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Telephone_Home] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Telephone_Mobile] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Telephone_Other] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Email_Address] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Date_Started] [datetime] NULL ,
[IND_Trading_Name] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Description_Proposed] [text] COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Profile] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_DD_Economic_Activity_ID] [numeric](18, 0) NULL ,
[IND_DD_Referal_Source_Code] [numeric](18, 0) NULL ,
[IND_DD_Training_Status_ID] [numeric](18, 0) NULL ,
[IND_DD_Age_ID] [numeric](18, 0) NULL ,
[IND_DD_Potential_Business_Type_ID] [numeric](18, 0) NULL ,
[IND_DD_Exit_ID] [numeric](18, 0) NULL ,
[IND_DD_Disadvantage_ID] [numeric](18, 0) NULL ,
[IND_DD_Bank_ID] [numeric](18, 0) NULL ,
[IND_DD_Start_Up_Confirmation_ID] [numeric](18, 0) NULL ,
[IND_DD_Growth_Potential_ID] [numeric](18, 0) NULL ,
[IND_DD_Ethnicity_ID] [numeric](18, 0) NULL ,
[IND_DD_Marital_Status_ID] [numeric](18, 0) NULL ,
[IND_DD_Gender_ID] [numeric](18, 0) NULL ,
[IND_DD_Status_ID] [numeric](18, 0) NULL ,
[IND_Related_To_Another] [varchar] (3) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_DD_Business_Status_ID] [numeric](18, 0) NULL ,
[IND_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Courses] (
[COURSE_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_Date_Entered] [datetime] NOT NULL ,
[COURSE_Title] [varchar] (255) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[COURSE_Description] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,
[COURSE_Last_Modified] [datetime] NULL
CREATE TABLE [dbo].[SYS_Courses_Venues] (
[COURSE_VEN_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_VEN_Date_Entered] [datetime] NOT NULL ,
[COURSE_VEN_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,
[COURSE_VEN_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Courses_TimeTable] (
[COURSE_TT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_TT_Date_Entered] [datetime] NOT NULL ,
[COURSE_TT_Date] [datetime] NOT NULL
CREATE TABLE [dbo].[SYS_Courses_Tutors] (
[COURSE_TUT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_TUT_Date_Entered] [datetime] NOT NULL ,
[COURSE_TUT_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[COURSE_TUT_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[COURSE_TUT_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Xref_Join_Courses] (
[XREF_Courses_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[XREF_Courses_Date_Entered] [datetime] NOT NULL ,
[COURSE_ID] [numeric](18, 0) NOT NULL ,
[COURSE_VEN_ID] [numeric](18, 0) NOT NULL ,
[COURSE_TT_ID] [numeric](18, 0) NOT NULL ,
[COURSE_TUT_ID] [numeric](18, 0) NOT NULL ,
[XREF_Courses_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Xref_Join_Ind_Courses] (
[XREF_Ind_Course_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[XREF_Ind_Course_Date_Entered] [datetime] NOT NULL ,
[IND_ID] [numeric](18, 0) NOT NULL ,
[XREF_Courses_ID] [numeric](18, 0) NOT NULL ,
[XREF_Ind_Course_Last_Updated] [datetime] NULL
Now for the View:
VIEW 5:
CREATE VIEW dbo.SYS_Individual_Course_List
AS
SELECT dbo.SYS_Individual.IND_First_Name,
dbo.SYS_Individual.IND_Surname, dbo.SYS_Courses.COURSE_Title,
dbo.SYS_Courses_Venues.COURSE_VEN_Address,
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID
FROM dbo.SYS_Courses_Venues INNER JOIN
dbo.SYS_Courses INNER JOIN
dbo.SYS_Xref_Join_Ind_Courses INNER JOIN
dbo.SYS_Individual ON
dbo.SYS_Xref_Join_Ind_Courses.IND_ID = dbo.SYS_Individual.IND_ID INNER JOIN
dbo.SYS_Xref_Join_Courses ON
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID =
dbo.SYS_Xref_Join_Courses.XREF_Courses_ID ON
dbo.SYS_Courses.COURSE_ID =
dbo.SYS_Xref_Join_Courses.COURSE_ID INNER JOIN
dbo.SYS_Courses_TimeTable ON
dbo.SYS_Xref_Join_Courses.COURSE_TT_ID =
dbo.SYS_Courses_TimeTable.COURSE_TT_ID INNER JOIN
dbo.SYS_Courses_Tutors ON
dbo.SYS_Xref_Join_Courses.COURSE_TUT_ID =
dbo.SYS_Courses_Tutors.COURSE_TUT_ID ON
dbo.SYS_Courses_Venues.COURSE_VEN_ID =
dbo.SYS_Xref_Join_Courses.COURSE_VEN_ID
Keith et al:

> I am having a problem creating a many-to-many-to-many type relationship.
It
In a single word: `No shit'. This is by design.

> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does
not
> generate the results I expected.
You should not have expected it to work in the First Place.
If you need to create a many-to-many relationship between relations A and
B, then we create a third relation C.
Intersect relations A and B with C (that is C accepts foreign keys from
relations A and B).
Since relation C should only contain the foreign key attributes from
relations A and B you should be able to figure out how to work with it.
Do not include DDL/source-code in usenet posts. People will try to
correct your code instead of your broken logic. For best results do not
even mention your `specific implementation'.
Have fun with your new `toy',
Timothy J. Bruce
uniblab@.hotmail.com
</RANT>
|||"Keith" <@..> wrote in message
news:uzMhc.32757$h44.4860659@.stones.force9.net...
> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does not
> generate the results I expected.
>
> Below if the DDL for the tables and the SQL for the view.
>
> Any help would be most appreciated.
>
>
> Many thanks in advance.
>
> Regards
>
> Keith
>
<snip>
See the reply to your previous post - as Jacco suggested, it seems that you
are using inner joins where you should be using outer joins. I suggest you
check out the examples of outer joins in Books Online, so you can see how
they work using a simple example. Your solution will probably involve left
joins from SYS_Individual to the other tables.
Simon
|||>> I am having a problem creating a many-to-many-to-many type
relationship. It
works fine, .. <<
No, you seem to have 5NF problems. You cannot create a true three-way
relationship as a series of binary relationships; look up join-project
normal forms.
But you have a lot of other problems.
1) Why did you make everything NUMERIC(18,0)? Think about what an
amazing thing that would be if reality was like that.
2) Why did you use IDENTITY instead of looking for real keys?
3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
lack of any industry standards for columns, etc.
4) Why put physical history into the tables? There are tools for
that.
5) Isn't a venue an attribute of a course?
6) What is the logical meaning of those XREF tables in terms of a
logical data model?
7) What is a "_type_id"? An attribute is either a type or it is an
identifier, but never both. Again, you don't understand the
differences between data and metadata, so you mix them in wreird ways.
Your DDL ought to look more like this:
CREATE TABLE IndividualCourses
(ssn CHAR(9) NOT NULL
REFERENCES Individuals (ssn)
ON UPDATE CASCADE
ON DELETE CASCADE,
course_id CHAR(5) NOT NULL)
REFERENCES Courses(course_id)
ON UPDATE CASCADE
ON DELETE CASCADE,
PRIMARY KEY (ssn, course_id));
You need constraints, defaults, real keys, logical names, etc. Start
over and get a book on data modeling.
|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.c om...
> relationship. It
> works fine, .. <<
> No, you seem to have 5NF problems. You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.
> But you have a lot of other problems.
> 1) Why did you make everything NUMERIC(18,0)? Think about what an
> amazing thing that would be if reality was like that.
> 2) Why did you use IDENTITY instead of looking for real keys?
> 3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
> lack of any industry standards for columns, etc.
> 4) Why put physical history into the tables? There are tools for
> that.
> 5) Isn't a venue an attribute of a course?
> 6) What is the logical meaning of those XREF tables in terms of a
> logical data model?
> 7) What is a "_type_id"? An attribute is either a type or it is an
> identifier, but never both. Again, you don't understand the
> differences between data and metadata, so you mix them in wreird ways.
> Your DDL ought to look more like this:
> CREATE TABLE IndividualCourses
> (ssn CHAR(9) NOT NULL
> REFERENCES Individuals (ssn)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> course_id CHAR(5) NOT NULL)
> REFERENCES Courses(course_id)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> PRIMARY KEY (ssn, course_id));
> You need constraints, defaults, real keys, logical names, etc. Start
> over and get a book on data modeling.
Just from curiosity - and I don't claim to have any answer to this question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not where
they were born.
Simon
|||Timothy J. Bruce wrote:
[]
> Do not include DDL/source-code in usenet posts. People will try to
> correct your code instead of your broken logic. For best results do not
> even mention your `specific implementation'.
> Have fun with your new `toy',
> Timothy J. Bruce
> uniblab@.hotmail.com
> </RANT>
>
That's rather poor advice. What posters should do is present as simple a
sample of the problem as possible, including standard SQL. Mentioning the
specific tools and environment used would be helpful.
The related suggestion is that posters should post DBMS specific questions in
the specific area and general questions in the general area. IOW, they should
post on topic questions.
How many ORACLE or SQL SERVER specific questions have we seen here in the
generic comp.databases group? Too many. So the original poster on this thread
was misguided in his posting to both specific SQL SERVER groups and to the
comp.databases group. Such a posting is nearly always off topic in one or the
other group.
Since his question was about relations and not SQL SERVER syntax, the
generic databases group is more appropriate.
If replies are just picking apart syntax, then I would suggest they are off
topic in the comp.databases group (unless maybe they are pointing out
something is not Standard SQL).
Bottom line is:
1. post to the appropriate group (goes for both original and reply posting)
2. post as complete and succuint information as possible (including your
platform DB and OS) for the comp.databases group.
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost
|||Simon Hayes wrote:
[]
> Just from curiosity - and I don't claim to have any answer to this question
> myself - what primary key would you use for European students? The SSN
> doesn't exist, and students routinely study in a country which is not where
> they were born.
> Simon
>
Don't use SSN, assign a unique student ID.
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost
|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.c om...
> relationship. It
> works fine, .. <<
>
You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.
>
Yes, you can- sometimes (often?). See
http://www.cis.drexel.edu/faculty/song/Papers/Jdb99.pdf
|||>> Just from curiosity - and I don't claim to have any answer to this
question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not
where they were born. <<
1) New York State used to make them get an SSN.
2) Use the holes in the Social Security Number. The SSN is composed of
3 parts, XXX-XX-XXXX, called the Area, Group, and Serial. The areas
are assigned as follows:
000 unused
627-699 unassigned, for future use
729-899 unassigned, for future use
900-999 not valid SSNs
3) invent a number if your state has privacy laws that require the SSN
not be used.
|||Ed Prochak <ed.prochak@.magicinterface.com> wrote:
[vbcol=seagreen]
>Timothy J. Bruce wrote:
>[]

>That's rather poor advice. What posters should do is present as simple a
>sample of the problem as possible, including standard SQL. Mentioning the
>specific tools and environment used would be helpful.
I will second this most strenuously. Details help. For example,
sometimes, a problem is due to a bug with a particular version of a
particular DBMS. If a poster is going to make me guess about details
like this, I guess I will probably just move on to the next post.
[snip]
Sincerely,
Gene Wirchenko
Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Help with Many-to-Many-to-Many Problem

I am having a problem creating a many-to-many-to-many type relationship. It
works fine, but when I create a view to query it and test it, it does not
generate the results I expected.

Below if the DDL for the tables and the SQL for the view.

Any help would be most appreciated.

Many thanks in advance.

Regards

Keith

DIAGRAM 5: SYS_Relationship_Individuals_Courses
(http://www.step-online.org.uk/diagram5.png)

This is the relationship I am having a problem with. Each individual can
attend many courses. I have tried to model this by creating this diagram.
It has the following tables in it. SYS_Individual (to show individuals).
To show courses (which already have a many-to-many relationship
(http://www.step-online.org.uk/diagram2.png), I added all the same tables as
in diagram 2 - SYS_Courses, SYS_Courses_Venues, SYS_Courses_TimeTable,
SYS_Courses_Tutors (joined using SYS_Xref_Join_Courses). Now as each
individual could attend many courses, I assumed that the correct way to
model this would be by creating another many-to-many between the
SYS_Individual table and the SYS_Xref_Join_Courses by using a new join table
(SYS_Xref_Join_Ind_Courses).

I tried to check this works using a view (SYS_Individual_Courses_List) -
VIEW 5 below.

The problem is that no matter how many entries I put in the
SYS_Xref_Join_Ind_Courses, the test view (VIEW 5 below), only ever shows one
record. While playing around with the view, I got it to show all the
entries, but they were duplicated 4 times each! I can't remember how I did
this now either.

Now for the DDL for the tables:

CREATE TABLE [do].[SYS_Individual] (

[IND_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[IND_Date_Entered] [datetime] NOT NULL ,

[IND_Date_on_Project] [datetime] NULL ,

[IND_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Post_Code] [varchar] (10) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Telephone_Home] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Telephone_Mobile] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Telephone_Other] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Email_Address] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Date_Started] [datetime] NULL ,

[IND_Trading_Name] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Description_Proposed] [text] COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Profile] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_DD_Economic_Activity_ID] [numeric](18, 0) NULL ,

[IND_DD_Referal_Source_Code] [numeric](18, 0) NULL ,

[IND_DD_Training_Status_ID] [numeric](18, 0) NULL ,

[IND_DD_Age_ID] [numeric](18, 0) NULL ,

[IND_DD_Potential_Business_Type_ID] [numeric](18, 0) NULL ,

[IND_DD_Exit_ID] [numeric](18, 0) NULL ,

[IND_DD_Disadvantage_ID] [numeric](18, 0) NULL ,

[IND_DD_Bank_ID] [numeric](18, 0) NULL ,

[IND_DD_Start_Up_Confirmation_ID] [numeric](18, 0) NULL ,

[IND_DD_Growth_Potential_ID] [numeric](18, 0) NULL ,

[IND_DD_Ethnicity_ID] [numeric](18, 0) NULL ,

[IND_DD_Marital_Status_ID] [numeric](18, 0) NULL ,

[IND_DD_Gender_ID] [numeric](18, 0) NULL ,

[IND_DD_Status_ID] [numeric](18, 0) NULL ,

[IND_Related_To_Another] [varchar] (3) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_DD_Business_Status_ID] [numeric](18, 0) NULL ,

[IND_Last_Updated] [datetime] NULL

CREATE TABLE [dbo].[SYS_Courses] (

[COURSE_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[COURSE_Date_Entered] [datetime] NOT NULL ,

[COURSE_Title] [varchar] (255) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[COURSE_Description] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,

[COURSE_Last_Modified] [datetime] NULL

CREATE TABLE [dbo].[SYS_Courses_Venues] (

[COURSE_VEN_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[COURSE_VEN_Date_Entered] [datetime] NOT NULL ,

[COURSE_VEN_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,

[COURSE_VEN_Last_Updated] [datetime] NULL

CREATE TABLE [dbo].[SYS_Courses_TimeTable] (

[COURSE_TT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[COURSE_TT_Date_Entered] [datetime] NOT NULL ,

[COURSE_TT_Date] [datetime] NOT NULL

CREATE TABLE [dbo].[SYS_Courses_Tutors] (

[COURSE_TUT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[COURSE_TUT_Date_Entered] [datetime] NOT NULL ,

[COURSE_TUT_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[COURSE_TUT_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[COURSE_TUT_Last_Updated] [datetime] NULL

CREATE TABLE [dbo].[SYS_Xref_Join_Courses] (

[XREF_Courses_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[XREF_Courses_Date_Entered] [datetime] NOT NULL ,

[COURSE_ID] [numeric](18, 0) NOT NULL ,

[COURSE_VEN_ID] [numeric](18, 0) NOT NULL ,

[COURSE_TT_ID] [numeric](18, 0) NOT NULL ,

[COURSE_TUT_ID] [numeric](18, 0) NOT NULL ,

[XREF_Courses_Last_Updated] [datetime] NULL

CREATE TABLE [dbo].[SYS_Xref_Join_Ind_Courses] (

[XREF_Ind_Course_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[XREF_Ind_Course_Date_Entered] [datetime] NOT NULL ,

[IND_ID] [numeric](18, 0) NOT NULL ,

[XREF_Courses_ID] [numeric](18, 0) NOT NULL ,

[XREF_Ind_Course_Last_Updated] [datetime] NULL

Now for the View:

VIEW 5:

CREATE VIEW dbo.SYS_Individual_Course_List

AS

SELECT dbo.SYS_Individual.IND_First_Name,
dbo.SYS_Individual.IND_Surname, dbo.SYS_Courses.COURSE_Title,

dbo.SYS_Courses_Venues.COURSE_VEN_Address,
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID

FROM dbo.SYS_Courses_Venues INNER JOIN

dbo.SYS_Courses INNER JOIN

dbo.SYS_Xref_Join_Ind_Courses INNER JOIN

dbo.SYS_Individual ON
dbo.SYS_Xref_Join_Ind_Courses.IND_ID = dbo.SYS_Individual.IND_ID INNER JOIN

dbo.SYS_Xref_Join_Courses ON
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID =
dbo.SYS_Xref_Join_Courses.XREF_Courses_ID ON

dbo.SYS_Courses.COURSE_ID =
dbo.SYS_Xref_Join_Courses.COURSE_ID INNER JOIN

dbo.SYS_Courses_TimeTable ON
dbo.SYS_Xref_Join_Courses.COURSE_TT_ID =
dbo.SYS_Courses_TimeTable.COURSE_TT_ID INNER JOIN

dbo.SYS_Courses_Tutors ON
dbo.SYS_Xref_Join_Courses.COURSE_TUT_ID =
dbo.SYS_Courses_Tutors.COURSE_TUT_ID ON

dbo.SYS_Courses_Venues.COURSE_VEN_ID =
dbo.SYS_Xref_Join_Courses.COURSE_VEN_ID>> I am having a problem creating a many-to-many-to-many type
relationship. It
works fine, .. <<

No, you seem to have 5NF problems. You cannot create a true three-way
relationship as a series of binary relationships; look up join-project
normal forms.

But you have a lot of other problems.

1) Why did you make everything NUMERIC(18,0)? Think about what an
amazing thing that would be if reality was like that.

2) Why did you use IDENTITY instead of looking for real keys??

3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
lack of any industry standards for columns, etc.

4) Why put physical history into the tables? There are tools for
that.

5) Isn't a venue an attribute of a course?

6) What is the logical meaning of those XREF tables in terms of a
logical data model?

7) What is a "_type_id"?? An attribute is either a type or it is an
identifier, but never both. Again, you don't understand the
differences between data and metadata, so you mix them in wreird ways.

Your DDL ought to look more like this:

CREATE TABLE IndividualCourses
(ssn CHAR(9) NOT NULL
REFERENCES Individuals (ssn)
ON UPDATE CASCADE
ON DELETE CASCADE,
course_id CHAR(5) NOT NULL)
REFERENCES Courses(course_id)
ON UPDATE CASCADE
ON DELETE CASCADE,
PRIMARY KEY (ssn, course_id));

You need constraints, defaults, real keys, logical names, etc. Start
over and get a book on data modeling.|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.c om...
> >> I am having a problem creating a many-to-many-to-many type
> relationship. It
> works fine, .. <<
> No, you seem to have 5NF problems. You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.
> But you have a lot of other problems.
> 1) Why did you make everything NUMERIC(18,0)? Think about what an
> amazing thing that would be if reality was like that.
> 2) Why did you use IDENTITY instead of looking for real keys??
> 3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
> lack of any industry standards for columns, etc.
> 4) Why put physical history into the tables? There are tools for
> that.
> 5) Isn't a venue an attribute of a course?
> 6) What is the logical meaning of those XREF tables in terms of a
> logical data model?
> 7) What is a "_type_id"?? An attribute is either a type or it is an
> identifier, but never both. Again, you don't understand the
> differences between data and metadata, so you mix them in wreird ways.
> Your DDL ought to look more like this:
> CREATE TABLE IndividualCourses
> (ssn CHAR(9) NOT NULL
> REFERENCES Individuals (ssn)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> course_id CHAR(5) NOT NULL)
> REFERENCES Courses(course_id)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> PRIMARY KEY (ssn, course_id));
> You need constraints, defaults, real keys, logical names, etc. Start
> over and get a book on data modeling.

Just from curiosity - and I don't claim to have any answer to this question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not where
they were born.

Simon|||Keith et al:

> I am having a problem creating a many-to-many-to-many type relationship.
It
In a single word: `No shit'. This is by design.

> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does
not
> generate the results I expected.
You should not have expected it to work in the First Place.
If you need to create a many-to-many relationship between relations A and
B, then we create a third relation C.
Intersect relations A and B with C (that is C accepts foreign keys from
relations A and B).
Since relation C should only contain the foreign key attributes from
relations A and B you should be able to figure out how to work with it.

Do not include DDL/source-code in usenet posts. People will try to
correct your code instead of your broken logic. For best results do not
even mention your `specific implementation'.

Have fun with your new `toy',
Timothy J. Bruce
uniblab@.hotmail.com
</RANT|||"Keith" <@..> wrote in message
news:uzMhc.32757$h44.4860659@.stones.force9.net...
> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does not
> generate the results I expected.
>
> Below if the DDL for the tables and the SQL for the view.
>
> Any help would be most appreciated.
>
>
> Many thanks in advance.
>
> Regards
>
> Keith

<snip
See the reply to your previous post - as Jacco suggested, it seems that you
are using inner joins where you should be using outer joins. I suggest you
check out the examples of outer joins in Books Online, so you can see how
they work using a simple example. Your solution will probably involve left
joins from SYS_Individual to the other tables.

Simon|||>> Just from curiosity - and I don't claim to have any answer to this
question myself - what primary key would you use for European students?
The SSN doesn't exist, and students routinely study in a country which
is not where they were born. <<

Years ago, the policy in many US universities was to make all students
get a Social Security Number (ssn); you needed one to work anyway.

Later, schools kept a block of bogus SSNs. The Social Security Number
(SSN) is composed of 3 parts, XXX-XX-XXXX, called the Area, Group, and
Serial. For the most part, (there are exceptions), the Area is
determined by where the individual APPLIED for the SSN (before 1972) or
RESIDED at time of application (after 1972). The "bogus" areas are
assigned as follows:

000 unused
627-699 unassigned, for future use
700-728 Railroad workers through 1963, then discontinued. Anyone in
the Railroad retirement program is now dead, over 120 years of age or
converted to an SSN.
729-899 unassigned, for future use.
900-999 not valid SSNs, but were used for program purposes when state
aid to the aged, blind and disabled was converted to a federal program
administered by SSA. Again, this goes back to the 1930's and as far as I
know anyone in those programs is now dead or converted to an SSN.

The 627-699 areas let you treat each foreign student group separately
with its own area number.

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||>Years ago, the policy in many US universities was to make all students
>get a Social Security Number (ssn); you needed one to work anyway.
>Later, schools kept a block of bogus SSNs. The Social Security Number
>(SSN) is composed of 3 parts, XXX-XX-XXXX, called the Area, Group, and
>Serial. For the most part, (there are exceptions), the Area is
>determined by where the individual APPLIED for the SSN (before 1972) or
>RESIDED at time of application (after 1972). The "bogus" areas are
>assigned as follows:
> 000 unused
> 627-699 unassigned, for future use
> 700-728 Railroad workers through 1963, then discontinued. Anyone in
>the Railroad retirement program is now dead, over 120 years of age or
>converted to an SSN.
> 729-899 unassigned, for future use.
> 900-999 not valid SSNs, but were used for program purposes when state
>aid to the aged, blind and disabled was converted to a federal program
>administered by SSA. Again, this goes back to the 1930's and as far as I
>know anyone in those programs is now dead or converted to an SSN.
>The 627-699 areas let you treat each foreign student group separately
>with its own area number.
>--CELKO--

Very enlightning. Thanks.
Got any more info or links where I can find out more info on this.

Randy
http://members.aol.com/rsmeiner|||>> Got any more info or links where I can find out more info on this. <<

Try doing a Google and go to the SSA site.

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||>>> Got any more info or links where I can find out more info on this. <<
>Try doing a Google and go to the SSA site.
>--CELKO--

You mean you actually expect me to do my own research ?
Well, ok.

Randy
http://members.aol.com/rsmeiner|||"RSMEINER" <rsmeiner@.aol.comcrap> wrote in message
news:20040425123019.27697.00000064@.mb-m17.aol.com...
> >Years ago, the policy in many US universities was to make all students
> >get a Social Security Number (ssn); you needed one to work anyway.

Years ago. This is no longer true, as places like NYS outlawed that use.

RPI had to convert to a new internal ID.

So, SSN may not always be a great choice.

However, as Joe's sure to ask or point out, the RPI assigned ID exists
independent of any single database.

i.e. they're not using some random IDENTITY field and going from there.|||Timothy J. Bruce wrote:

[]
> Do not include DDL/source-code in usenet posts. People will try to
> correct your code instead of your broken logic. For best results do not
> even mention your `specific implementation'.
> Have fun with your new `toy',
> Timothy J. Bruce
> uniblab@.hotmail.com
> </RANT>
>
That's rather poor advice. What posters should do is present as simple a
sample of the problem as possible, including standard SQL. Mentioning the
specific tools and environment used would be helpful.

The related suggestion is that posters should post DBMS specific questions in
the specific area and general questions in the general area. IOW, they should
post on topic questions.

How many ORACLE or SQL SERVER specific questions have we seen here in the
generic comp.databases group? Too many. So the original poster on this thread
was misguided in his posting to both specific SQL SERVER groups and to the
comp.databases group. Such a posting is nearly always off topic in one or the
other group.

Since his question was about relations and not SQL SERVER syntax, the
generic databases group is more appropriate.

If replies are just picking apart syntax, then I would suggest they are off
topic in the comp.databases group (unless maybe they are pointing out
something is not Standard SQL).

Bottom line is:
1. post to the appropriate group (goes for both original and reply posting)
2. post as complete and succuint information as possible (including your
platform DB and OS) for the comp.databases group.

--
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost|||Simon Hayes wrote:

[]
> Just from curiosity - and I don't claim to have any answer to this question
> myself - what primary key would you use for European students? The SSN
> doesn't exist, and students routinely study in a country which is not where
> they were born.
> Simon
>
Don't use SSN, assign a unique student ID.

--
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.c om...
> >> I am having a problem creating a many-to-many-to-many type
> relationship. It
> works fine, .. <<
You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.

Yes, you can- sometimes (often?). See
http://www.cis.drexel.edu/faculty/song/Papers/Jdb99.pdf|||>> I am having a problem creating a many-to-many-to-many type
relationship. It
works fine, .. <<

No, you seem to have 5NF problems. You cannot create a true three-way
relationship as a series of binary relationships; look up join-project
normal forms.

But you have a lot of other problems.

1) Why did you make everything NUMERIC(18,0)? Think about what an
amazing thing that would be if reality was like that.

2) Why did you use IDENTITY instead of looking for real keys??

3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
lack of any industry standards for columns, etc.

4) Why put physical history into the tables? There are tools for
that.

5) Isn't a venue an attribute of a course?

6) What is the logical meaning of those XREF tables in terms of a
logical data model?

7) What is a "_type_id"?? An attribute is either a type or it is an
identifier, but never both. Again, you don't understand the
differences between data and metadata, so you mix them in wreird ways.

Your DDL ought to look more like this:

CREATE TABLE IndividualCourses
(ssn CHAR(9) NOT NULL
REFERENCES Individuals (ssn)
ON UPDATE CASCADE
ON DELETE CASCADE,
course_id CHAR(5) NOT NULL)
REFERENCES Courses(course_id)
ON UPDATE CASCADE
ON DELETE CASCADE,
PRIMARY KEY (ssn, course_id));

You need constraints, defaults, real keys, logical names, etc. Start
over and get a book on data modeling.|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.c om...
> >> I am having a problem creating a many-to-many-to-many type
> relationship. It
> works fine, .. <<
> No, you seem to have 5NF problems. You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.
> But you have a lot of other problems.
> 1) Why did you make everything NUMERIC(18,0)? Think about what an
> amazing thing that would be if reality was like that.
> 2) Why did you use IDENTITY instead of looking for real keys??
> 3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
> lack of any industry standards for columns, etc.
> 4) Why put physical history into the tables? There are tools for
> that.
> 5) Isn't a venue an attribute of a course?
> 6) What is the logical meaning of those XREF tables in terms of a
> logical data model?
> 7) What is a "_type_id"?? An attribute is either a type or it is an
> identifier, but never both. Again, you don't understand the
> differences between data and metadata, so you mix them in wreird ways.
> Your DDL ought to look more like this:
> CREATE TABLE IndividualCourses
> (ssn CHAR(9) NOT NULL
> REFERENCES Individuals (ssn)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> course_id CHAR(5) NOT NULL)
> REFERENCES Courses(course_id)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> PRIMARY KEY (ssn, course_id));
> You need constraints, defaults, real keys, logical names, etc. Start
> over and get a book on data modeling.

Just from curiosity - and I don't claim to have any answer to this question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not where
they were born.

Simon|||>> Just from curiosity - and I don't claim to have any answer to this
question myself - what primary key would you use for European students?
The SSN doesn't exist, and students routinely study in a country which
is not where they were born. <<

Years ago, the policy in many US universities was to make all students
get a Social Security Number (ssn); you needed one to work anyway.

Later, schools kept a block of bogus SSNs. The Social Security Number
(SSN) is composed of 3 parts, XXX-XX-XXXX, called the Area, Group, and
Serial. For the most part, (there are exceptions), the Area is
determined by where the individual APPLIED for the SSN (before 1972) or
RESIDED at time of application (after 1972). The "bogus" areas are
assigned as follows:

000 unused
627-699 unassigned, for future use
700-728 Railroad workers through 1963, then discontinued. Anyone in
the Railroad retirement program is now dead, over 120 years of age or
converted to an SSN.
729-899 unassigned, for future use.
900-999 not valid SSNs, but were used for program purposes when state
aid to the aged, blind and disabled was converted to a federal program
administered by SSA. Again, this goes back to the 1930's and as far as I
know anyone in those programs is now dead or converted to an SSN.

The 627-699 areas let you treat each foreign student group separately
with its own area number.

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||>Years ago, the policy in many US universities was to make all students
>get a Social Security Number (ssn); you needed one to work anyway.
>Later, schools kept a block of bogus SSNs. The Social Security Number
>(SSN) is composed of 3 parts, XXX-XX-XXXX, called the Area, Group, and
>Serial. For the most part, (there are exceptions), the Area is
>determined by where the individual APPLIED for the SSN (before 1972) or
>RESIDED at time of application (after 1972). The "bogus" areas are
>assigned as follows:
> 000 unused
> 627-699 unassigned, for future use
> 700-728 Railroad workers through 1963, then discontinued. Anyone in
>the Railroad retirement program is now dead, over 120 years of age or
>converted to an SSN.
> 729-899 unassigned, for future use.
> 900-999 not valid SSNs, but were used for program purposes when state
>aid to the aged, blind and disabled was converted to a federal program
>administered by SSA. Again, this goes back to the 1930's and as far as I
>know anyone in those programs is now dead or converted to an SSN.
>The 627-699 areas let you treat each foreign student group separately
>with its own area number.
>--CELKO--

Very enlightning. Thanks.
Got any more info or links where I can find out more info on this.

Randy
http://members.aol.com/rsmeiner|||>> Got any more info or links where I can find out more info on this. <<

Try doing a Google and go to the SSA site.

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||>>> Got any more info or links where I can find out more info on this. <<
>Try doing a Google and go to the SSA site.
>--CELKO--

You mean you actually expect me to do my own research ?
Well, ok.

Randy
http://members.aol.com/rsmeiner|||"RSMEINER" <rsmeiner@.aol.comcrap> wrote in message
news:20040425123019.27697.00000064@.mb-m17.aol.com...
> >Years ago, the policy in many US universities was to make all students
> >get a Social Security Number (ssn); you needed one to work anyway.

Years ago. This is no longer true, as places like NYS outlawed that use.

RPI had to convert to a new internal ID.

So, SSN may not always be a great choice.

However, as Joe's sure to ask or point out, the RPI assigned ID exists
independent of any single database.

i.e. they're not using some random IDENTITY field and going from there.|||Timothy J. Bruce wrote:

[]
> Do not include DDL/source-code in usenet posts. People will try to
> correct your code instead of your broken logic. For best results do not
> even mention your `specific implementation'.
> Have fun with your new `toy',
> Timothy J. Bruce
> uniblab@.hotmail.com
> </RANT>
>
That's rather poor advice. What posters should do is present as simple a
sample of the problem as possible, including standard SQL. Mentioning the
specific tools and environment used would be helpful.

The related suggestion is that posters should post DBMS specific questions in
the specific area and general questions in the general area. IOW, they should
post on topic questions.

How many ORACLE or SQL SERVER specific questions have we seen here in the
generic comp.databases group? Too many. So the original poster on this thread
was misguided in his posting to both specific SQL SERVER groups and to the
comp.databases group. Such a posting is nearly always off topic in one or the
other group.

Since his question was about relations and not SQL SERVER syntax, the
generic databases group is more appropriate.

If replies are just picking apart syntax, then I would suggest they are off
topic in the comp.databases group (unless maybe they are pointing out
something is not Standard SQL).

Bottom line is:
1. post to the appropriate group (goes for both original and reply posting)
2. post as complete and succuint information as possible (including your
platform DB and OS) for the comp.databases group.

--
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost|||Simon Hayes wrote:

[]
> Just from curiosity - and I don't claim to have any answer to this question
> myself - what primary key would you use for European students? The SSN
> doesn't exist, and students routinely study in a country which is not where
> they were born.
> Simon
>
Don't use SSN, assign a unique student ID.

--
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.c om...
> >> I am having a problem creating a many-to-many-to-many type
> relationship. It
> works fine, .. <<
You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.

Yes, you can- sometimes (often?). See
http://www.cis.drexel.edu/faculty/song/Papers/Jdb99.pdf|||>> Just from curiosity - and I don't claim to have any answer to this
question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not
where they were born. <<

1) New York State used to make them get an SSN.

2) Use the holes in the Social Security Number. The SSN is composed of
3 parts, XXX-XX-XXXX, called the Area, Group, and Serial. The areas
are assigned as follows:

000 unused
627-699 unassigned, for future use
729-899 unassigned, for future use
900-999 not valid SSNs

3) invent a number if your state has privacy laws that require the SSN
not be used.|||>> Just from curiosity - and I don't claim to have any answer to this
question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not
where they were born. <<

1) New York State used to make them get an SSN.

2) Use the holes in the Social Security Number. The SSN is composed of
3 parts, XXX-XX-XXXX, called the Area, Group, and Serial. The areas
are assigned as follows:

000 unused
627-699 unassigned, for future use
729-899 unassigned, for future use
900-999 not valid SSNs

3) invent a number if your state has privacy laws that require the SSN
not be used.|||Ed Prochak <ed.prochak@.magicinterface.com> wrote:

>Timothy J. Bruce wrote:
>[]
>>
>> Do not include DDL/source-code in usenet posts. People will try to
>> correct your code instead of your broken logic. For best results do not
>> even mention your `specific implementation'.
>>
>> Have fun with your new `toy',
>> Timothy J. Bruce
>> uniblab@.hotmail.com
>> </RANT
>That's rather poor advice. What posters should do is present as simple a
>sample of the problem as possible, including standard SQL. Mentioning the
>specific tools and environment used would be helpful.

I will second this most strenuously. Details help. For example,
sometimes, a problem is due to a bug with a particular version of a
particular DBMS. If a poster is going to make me guess about details
like this, I guess I will probably just move on to the next post.

[snip]

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.|||joe.celko@.northface.edu (--CELKO--) wrote:

>>> Just from curiosity - and I don't claim to have any answer to this
>question
>myself - what primary key would you use for European students? The SSN
>doesn't exist, and students routinely study in a country which is not
>where they were born. <<
>1) New York State used to make them get an SSN.

What do you do in the meantime for a PK? I--a Canadian--apply for
admission, and you will not admit me because I do not have an SSN? I
think I would want to take database courses elsewhere then!

>2) Use the holes in the Social Security Number. The SSN is composed of
>3 parts, XXX-XX-XXXX, called the Area, Group, and Serial. The areas
>are assigned as follows:
> 000 unused
> 627-699 unassigned, for future use
> 729-899 unassigned, for future use
> 900-999 not valid SSNs

And if the definition changes?

>3) invent a number if your state has privacy laws that require the SSN
>not be used.

I think #3 is best. 1) If your jurisdictions do not have privacy
laws, it does not mean that they never will. Some came into effect in
Canada this last New Year's Day. 2) If it is Their number, what do
you do if They change it or its definition?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.|||Ed Prochak <ed.prochak@.magicinterface.com> wrote:

>Timothy J. Bruce wrote:
>[]
>>
>> Do not include DDL/source-code in usenet posts. People will try to
>> correct your code instead of your broken logic. For best results do not
>> even mention your `specific implementation'.
>>
>> Have fun with your new `toy',
>> Timothy J. Bruce
>> uniblab@.hotmail.com
>> </RANT
>That's rather poor advice. What posters should do is present as simple a
>sample of the problem as possible, including standard SQL. Mentioning the
>specific tools and environment used would be helpful.

I will second this most strenuously. Details help. For example,
sometimes, a problem is due to a bug with a particular version of a
particular DBMS. If a poster is going to make me guess about details
like this, I guess I will probably just move on to the next post.

[snip]

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.|||joe.celko@.northface.edu (--CELKO--) wrote:

>>> Just from curiosity - and I don't claim to have any answer to this
>question
>myself - what primary key would you use for European students? The SSN
>doesn't exist, and students routinely study in a country which is not
>where they were born. <<
>1) New York State used to make them get an SSN.

What do you do in the meantime for a PK? I--a Canadian--apply for
admission, and you will not admit me because I do not have an SSN? I
think I would want to take database courses elsewhere then!

>2) Use the holes in the Social Security Number. The SSN is composed of
>3 parts, XXX-XX-XXXX, called the Area, Group, and Serial. The areas
>are assigned as follows:
> 000 unused
> 627-699 unassigned, for future use
> 729-899 unassigned, for future use
> 900-999 not valid SSNs

And if the definition changes?

>3) invent a number if your state has privacy laws that require the SSN
>not be used.

I think #3 is best. 1) If your jurisdictions do not have privacy
laws, it does not mean that they never will. Some came into effect in
Canada this last New Year's Day. 2) If it is Their number, what do
you do if They change it or its definition?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Help with Many-to-Many-to-Many Problem

I am having a problem creating a many-to-many-to-many type relationship. It
works fine, but when I create a view to query it and test it, it does not
generate the results I expected.

Below if the DDL for the tables and the SQL for the view.

Any help would be most appreciated.

Many thanks in advance.

Regards

Keith

DIAGRAM 5: SYS_Relationship_Individuals_Courses
(http://www.step-online.org.uk/diagram5.png)

This is the relationship I am having a problem with. Each individual can
attend many courses. I have tried to model this by creating this diagram.
It has the following tables in it. SYS_Individual (to show individuals).
To show courses (which already have a many-to-many relationship
(http://www.step-online.org.uk/diagram2.png), I added all the same tables as
in diagram 2 - SYS_Courses, SYS_Courses_Venues, SYS_Courses_TimeTable,
SYS_Courses_Tutors (joined using SYS_Xref_Join_Courses). Now as each
individual could attend many courses, I assumed that the correct way to
model this would be by creating another many-to-many between the
SYS_Individual table and the SYS_Xref_Join_Courses by using a new join table
(SYS_Xref_Join_Ind_Courses).

I tried to check this works using a view (SYS_Individual_Courses_List) -
VIEW 5 below.

The problem is that no matter how many entries I put in the
SYS_Xref_Join_Ind_Courses, the test view (VIEW 5 below), only ever shows one
record. While playing around with the view, I got it to show all the
entries, but they were duplicated 4 times each! I can't remember how I did
this now either.

Now for the DDL for the tables:

CREATE TABLE [do].[SYS_Individual] (

[IND_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[IND_Date_Entered] [datetime] NOT NULL ,

[IND_Date_on_Project] [datetime] NULL ,

[IND_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Post_Code] [varchar] (10) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Telephone_Home] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Telephone_Mobile] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Telephone_Other] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Email_Address] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Date_Started] [datetime] NULL ,

[IND_Trading_Name] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Description_Proposed] [text] COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_Profile] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_DD_Economic_Activity_ID] [numeric](18, 0) NULL ,

[IND_DD_Referal_Source_Code] [numeric](18, 0) NULL ,

[IND_DD_Training_Status_ID] [numeric](18, 0) NULL ,

[IND_DD_Age_ID] [numeric](18, 0) NULL ,

[IND_DD_Potential_Business_Type_ID] [numeric](18, 0) NULL ,

[IND_DD_Exit_ID] [numeric](18, 0) NULL ,

[IND_DD_Disadvantage_ID] [numeric](18, 0) NULL ,

[IND_DD_Bank_ID] [numeric](18, 0) NULL ,

[IND_DD_Start_Up_Confirmation_ID] [numeric](18, 0) NULL ,

[IND_DD_Growth_Potential_ID] [numeric](18, 0) NULL ,

[IND_DD_Ethnicity_ID] [numeric](18, 0) NULL ,

[IND_DD_Marital_Status_ID] [numeric](18, 0) NULL ,

[IND_DD_Gender_ID] [numeric](18, 0) NULL ,

[IND_DD_Status_ID] [numeric](18, 0) NULL ,

[IND_Related_To_Another] [varchar] (3) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,

[IND_DD_Business_Status_ID] [numeric](18, 0) NULL ,

[IND_Last_Updated] [datetime] NULL

CREATE TABLE [dbo].[SYS_Courses] (

[COURSE_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[COURSE_Date_Entered] [datetime] NOT NULL ,

[COURSE_Title] [varchar] (255) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[COURSE_Description] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,

[COURSE_Last_Modified] [datetime] NULL

CREATE TABLE [dbo].[SYS_Courses_Venues] (

[COURSE_VEN_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[COURSE_VEN_Date_Entered] [datetime] NOT NULL ,

[COURSE_VEN_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,

[COURSE_VEN_Last_Updated] [datetime] NULL

CREATE TABLE [dbo].[SYS_Courses_TimeTable] (

[COURSE_TT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[COURSE_TT_Date_Entered] [datetime] NOT NULL ,

[COURSE_TT_Date] [datetime] NOT NULL

CREATE TABLE [dbo].[SYS_Courses_Tutors] (

[COURSE_TUT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[COURSE_TUT_Date_Entered] [datetime] NOT NULL ,

[COURSE_TUT_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[COURSE_TUT_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[COURSE_TUT_Last_Updated] [datetime] NULL

CREATE TABLE [dbo].[SYS_Xref_Join_Courses] (

[XREF_Courses_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[XREF_Courses_Date_Entered] [datetime] NOT NULL ,

[COURSE_ID] [numeric](18, 0) NOT NULL ,

[COURSE_VEN_ID] [numeric](18, 0) NOT NULL ,

[COURSE_TT_ID] [numeric](18, 0) NOT NULL ,

[COURSE_TUT_ID] [numeric](18, 0) NOT NULL ,

[XREF_Courses_Last_Updated] [datetime] NULL

CREATE TABLE [dbo].[SYS_Xref_Join_Ind_Courses] (

[XREF_Ind_Course_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,

[XREF_Ind_Course_Date_Entered] [datetime] NOT NULL ,

[IND_ID] [numeric](18, 0) NOT NULL ,

[XREF_Courses_ID] [numeric](18, 0) NOT NULL ,

[XREF_Ind_Course_Last_Updated] [datetime] NULL

Now for the View:

VIEW 5:

CREATE VIEW dbo.SYS_Individual_Course_List

AS

SELECT dbo.SYS_Individual.IND_First_Name,
dbo.SYS_Individual.IND_Surname, dbo.SYS_Courses.COURSE_Title,

dbo.SYS_Courses_Venues.COURSE_VEN_Address,
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID

FROM dbo.SYS_Courses_Venues INNER JOIN

dbo.SYS_Courses INNER JOIN

dbo.SYS_Xref_Join_Ind_Courses INNER JOIN

dbo.SYS_Individual ON
dbo.SYS_Xref_Join_Ind_Courses.IND_ID = dbo.SYS_Individual.IND_ID INNER JOIN

dbo.SYS_Xref_Join_Courses ON
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID =
dbo.SYS_Xref_Join_Courses.XREF_Courses_ID ON

dbo.SYS_Courses.COURSE_ID =
dbo.SYS_Xref_Join_Courses.COURSE_ID INNER JOIN

dbo.SYS_Courses_TimeTable ON
dbo.SYS_Xref_Join_Courses.COURSE_TT_ID =
dbo.SYS_Courses_TimeTable.COURSE_TT_ID INNER JOIN

dbo.SYS_Courses_Tutors ON
dbo.SYS_Xref_Join_Courses.COURSE_TUT_ID =
dbo.SYS_Courses_Tutors.COURSE_TUT_ID ON

dbo.SYS_Courses_Venues.COURSE_VEN_ID =
dbo.SYS_Xref_Join_Courses.COURSE_VEN_IDKeith et al:

> I am having a problem creating a many-to-many-to-many type relationship.
It
In a single word: `No shit'. This is by design.

> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does
not
> generate the results I expected.
You should not have expected it to work in the First Place.
If you need to create a many-to-many relationship between relations A and
B, then we create a third relation C.
Intersect relations A and B with C (that is C accepts foreign keys from
relations A and B).
Since relation C should only contain the foreign key attributes from
relations A and B you should be able to figure out how to work with it.

Do not include DDL/source-code in usenet posts. People will try to
correct your code instead of your broken logic. For best results do not
even mention your `specific implementation'.

Have fun with your new `toy',
Timothy J. Bruce
uniblab@.hotmail.com
</RANT|||"Keith" <@..> wrote in message
news:uzMhc.32757$h44.4860659@.stones.force9.net...
> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does not
> generate the results I expected.
>
> Below if the DDL for the tables and the SQL for the view.
>
> Any help would be most appreciated.
>
>
> Many thanks in advance.
>
> Regards
>
> Keith

<snip
See the reply to your previous post - as Jacco suggested, it seems that you
are using inner joins where you should be using outer joins. I suggest you
check out the examples of outer joins in Books Online, so you can see how
they work using a simple example. Your solution will probably involve left
joins from SYS_Individual to the other tables.

Simon

Help with Many-to-Many-to-Many Problem

I am having a problem creating a many-to-many-to-many type relationship. It
works fine, but when I create a view to query it and test it, it does not
generate the results I expected.
Below if the DDL for the tables and the SQL for the view.
Any help would be most appreciated.
Many thanks in advance.
Regards
Keith
DIAGRAM 5: SYS_Relationship_Individuals_Courses
(http://www.step-online.org.uk/diagram5.png)
This is the relationship I am having a problem with. Each individual can
attend many courses. I have tried to model this by creating this diagram.
It has the following tables in it. SYS_Individual (to show individuals).
To show courses (which already have a many-to-many relationship
(http://www.step-online.org.uk/diagram2.png), I added all the same tables as
in diagram 2 - SYS_Courses, SYS_Courses_Venues, SYS_Courses_TimeTable,
SYS_Courses_Tutors (joined using SYS_Xref_Join_Courses). Now as each
individual could attend many courses, I assumed that the correct way to
model this would be by creating another many-to-many between the
SYS_Individual table and the SYS_Xref_Join_Courses by using a new join table
(SYS_Xref_Join_Ind_Courses).
I tried to check this works using a view (SYS_Individual_Courses_List) -
VIEW 5 below.
The problem is that no matter how many entries I put in the
SYS_Xref_Join_Ind_Courses, the test view (VIEW 5 below), only ever shows one
record. While playing around with the view, I got it to show all the
entries, but they were duplicated 4 times each! I can't remember how I did
this now either.
Now for the DDL for the tables:
CREATE TABLE [do].[SYS_Individual] (
[IND_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[IND_Date_Entered] [datetime] NOT NULL ,
[IND_Date_on_Project] [datetime] NULL ,
[IND_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Post_Code] [varchar] (10) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Telephone_Home] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Telephone_Mobile] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Telephone_Other] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Email_Address] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Date_Started] [datetime] NULL ,
[IND_Trading_Name] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Description_Proposed] [text] COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Profile] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_DD_Economic_Activity_ID] [numeric](18, 0) NULL ,
[IND_DD_Referal_Source_Code] [numeric](18, 0) NULL ,
[IND_DD_Training_Status_ID] [numeric](18, 0) NULL ,
[IND_DD_Age_ID] [numeric](18, 0) NULL ,
[IND_DD_Potential_Business_Type_ID] [numeric](18, 0) NULL ,
[IND_DD_Exit_ID] [numeric](18, 0) NULL ,
[IND_DD_Disadvantage_ID] [numeric](18, 0) NULL ,
[IND_DD_Bank_ID] [numeric](18, 0) NULL ,
[IND_DD_Start_Up_Confirmation_ID] [numeric](18, 0) NULL ,
[IND_DD_Growth_Potential_ID] [numeric](18, 0) NULL ,
[IND_DD_Ethnicity_ID] [numeric](18, 0) NULL ,
[IND_DD_Marital_Status_ID] [numeric](18, 0) NULL ,
[IND_DD_Gender_ID] [numeric](18, 0) NULL ,
[IND_DD_Status_ID] [numeric](18, 0) NULL ,
[IND_Related_To_Another] [varchar] (3) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_DD_Business_Status_ID] [numeric](18, 0) NULL ,
[IND_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Courses] (
[COURSE_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_Date_Entered] [datetime] NOT NULL ,
[COURSE_Title] [varchar] (255) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[COURSE_Description] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,
[COURSE_Last_Modified] [datetime] NULL
CREATE TABLE [dbo].[SYS_Courses_Venues] (
[COURSE_VEN_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_VEN_Date_Entered] [datetime] NOT NULL ,
[COURSE_VEN_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,
[COURSE_VEN_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Courses_TimeTable] (
[COURSE_TT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_TT_Date_Entered] [datetime] NOT NULL ,
[COURSE_TT_Date] [datetime] NOT NULL
CREATE TABLE [dbo].[SYS_Courses_Tutors] (
[COURSE_TUT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_TUT_Date_Entered] [datetime] NOT NULL ,
[COURSE_TUT_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[COURSE_TUT_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[COURSE_TUT_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Xref_Join_Courses] (
[XREF_Courses_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[XREF_Courses_Date_Entered] [datetime] NOT NULL ,
[COURSE_ID] [numeric](18, 0) NOT NULL ,
[COURSE_VEN_ID] [numeric](18, 0) NOT NULL ,
[COURSE_TT_ID] [numeric](18, 0) NOT NULL ,
[COURSE_TUT_ID] [numeric](18, 0) NOT NULL ,
[XREF_Courses_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Xref_Join_Ind_Courses] (
[XREF_Ind_Course_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[XREF_Ind_Course_Date_Entered] [datetime] NOT NULL ,
[IND_ID] [numeric](18, 0) NOT NULL ,
[XREF_Courses_ID] [numeric](18, 0) NOT NULL ,
[XREF_Ind_Course_Last_Updated] [datetime] NULL
Now for the View:
VIEW 5:
CREATE VIEW dbo.SYS_Individual_Course_List
AS
SELECT dbo.SYS_Individual.IND_First_Name,
dbo.SYS_Individual.IND_Surname, dbo.SYS_Courses.COURSE_Title,
dbo.SYS_Courses_Venues.COURSE_VEN_Address,
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID
FROM dbo.SYS_Courses_Venues INNER JOIN
dbo.SYS_Courses INNER JOIN
dbo.SYS_Xref_Join_Ind_Courses INNER JOIN
dbo.SYS_Individual ON
dbo.SYS_Xref_Join_Ind_Courses.IND_ID = dbo.SYS_Individual.IND_ID INNER JOIN
dbo.SYS_Xref_Join_Courses ON
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID =
dbo.SYS_Xref_Join_Courses.XREF_Courses_ID ON
dbo.SYS_Courses.COURSE_ID =
dbo.SYS_Xref_Join_Courses.COURSE_ID INNER JOIN
dbo.SYS_Courses_TimeTable ON
dbo.SYS_Xref_Join_Courses.COURSE_TT_ID =
dbo.SYS_Courses_TimeTable.COURSE_TT_ID INNER JOIN
dbo.SYS_Courses_Tutors ON
dbo.SYS_Xref_Join_Courses.COURSE_TUT_ID =
dbo.SYS_Courses_Tutors.COURSE_TUT_ID ON
dbo.SYS_Courses_Venues.COURSE_VEN_ID =
dbo.SYS_Xref_Join_Courses.COURSE_VEN_IDKeith et al:

> I am having a problem creating a many-to-many-to-many type relationship.
It
In a single word: `No shit'. This is by design.

> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does
not
> generate the results I expected.
You should not have expected it to work in the First Place.
If you need to create a many-to-many relationship between relations A and
B, then we create a third relation C.
Intersect relations A and B with C (that is C accepts foreign keys from
relations A and B).
Since relation C should only contain the foreign key attributes from
relations A and B you should be able to figure out how to work with it.
Do not include DDL/source-code in usenet posts. People will try to
correct your code instead of your broken logic. For best results do not
even mention your `specific implementation'.
Have fun with your new `toy',
Timothy J. Bruce
uniblab@.hotmail.com
</RANT>|||"Keith" <@..> wrote in message
news:uzMhc.32757$h44.4860659@.stones.force9.net...
> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does not
> generate the results I expected.
>
> Below if the DDL for the tables and the SQL for the view.
>
> Any help would be most appreciated.
>
>
> Many thanks in advance.
>
> Regards
>
> Keith
>
<snip>
See the reply to your previous post - as Jacco suggested, it seems that you
are using inner joins where you should be using outer joins. I suggest you
check out the examples of outer joins in Books Online, so you can see how
they work using a simple example. Your solution will probably involve left
joins from SYS_Individual to the other tables.
Simon|||>> I am having a problem creating a many-to-many-to-many type
relationship. It
works fine, .. <<
No, you seem to have 5NF problems. You cannot create a true three-way
relationship as a series of binary relationships; look up join-project
normal forms.
But you have a lot of other problems.
1) Why did you make everything NUMERIC(18,0)? Think about what an
amazing thing that would be if reality was like that.
2) Why did you use IDENTITY instead of looking for real keys'
3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
lack of any industry standards for columns, etc.
4) Why put physical history into the tables? There are tools for
that.
5) Isn't a venue an attribute of a course?
6) What is the logical meaning of those XREF tables in terms of a
logical data model?
7) What is a "_type_id"' An attribute is either a type or it is an
identifier, but never both. Again, you don't understand the
differences between data and metadata, so you mix them in wreird ways.
Your DDL ought to look more like this:
CREATE TABLE IndividualCourses
(ssn CHAR(9) NOT NULL
REFERENCES Individuals (ssn)
ON UPDATE CASCADE
ON DELETE CASCADE,
course_id CHAR(5) NOT NULL)
REFERENCES Courses(course_id)
ON UPDATE CASCADE
ON DELETE CASCADE,
PRIMARY KEY (ssn, course_id));
You need constraints, defaults, real keys, logical names, etc. Start
over and get a book on data modeling.|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.com...
> relationship. It
> works fine, .. <<
> No, you seem to have 5NF problems. You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.
> But you have a lot of other problems.
> 1) Why did you make everything NUMERIC(18,0)? Think about what an
> amazing thing that would be if reality was like that.
> 2) Why did you use IDENTITY instead of looking for real keys'
> 3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
> lack of any industry standards for columns, etc.
> 4) Why put physical history into the tables? There are tools for
> that.
> 5) Isn't a venue an attribute of a course?
> 6) What is the logical meaning of those XREF tables in terms of a
> logical data model?
> 7) What is a "_type_id"' An attribute is either a type or it is an
> identifier, but never both. Again, you don't understand the
> differences between data and metadata, so you mix them in wreird ways.
> Your DDL ought to look more like this:
> CREATE TABLE IndividualCourses
> (ssn CHAR(9) NOT NULL
> REFERENCES Individuals (ssn)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> course_id CHAR(5) NOT NULL)
> REFERENCES Courses(course_id)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> PRIMARY KEY (ssn, course_id));
> You need constraints, defaults, real keys, logical names, etc. Start
> over and get a book on data modeling.
Just from curiosity - and I don't claim to have any answer to this question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not where
they were born.
Simon|||Timothy J. Bruce wrote:
[]
> Do not include DDL/source-code in usenet posts. People will try to
> correct your code instead of your broken logic. For best results do not
> even mention your `specific implementation'.
> Have fun with your new `toy',
> Timothy J. Bruce
> uniblab@.hotmail.com
> </RANT>
>
That's rather poor advice. What posters should do is present as simple a
sample of the problem as possible, including standard SQL. Mentioning the
specific tools and environment used would be helpful.
The related suggestion is that posters should post DBMS specific questions i
n
the specific area and general questions in the general area. IOW, they shoul
d
post on topic questions.
How many ORACLE or SQL SERVER specific questions have we seen here in the
generic comp.databases group? Too many. So the original poster on this threa
d
was misguided in his posting to both specific SQL SERVER groups and to the
comp.databases group. Such a posting is nearly always off topic in one or th
e
other group.
Since his question was about relations and not SQL SERVER syntax, the
generic databases group is more appropriate.
If replies are just picking apart syntax, then I would suggest they are off
topic in the comp.databases group (unless maybe they are pointing out
something is not Standard SQL).
Bottom line is:
1. post to the appropriate group (goes for both original and reply posting)
2. post as complete and succuint information as possible (including your
platform DB and OS) for the comp.databases group.
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost|||Simon Hayes wrote:
[]
> Just from curiosity - and I don't claim to have any answer to this questio
n
> myself - what primary key would you use for European students? The SSN
> doesn't exist, and students routinely study in a country which is not wher
e
> they were born.
> Simon
>
Don't use SSN, assign a unique student ID.
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.com...
> relationship. It
> works fine, .. <<
>
You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.
>
Yes, you can- sometimes (often?). See
http://www.cis.drexel.edu/faculty/song/Papers/Jdb99.pdf|||>> Just from curiosity - and I don't claim to have any answer to this
question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not
where they were born. <<
1) New York State used to make them get an SSN.
2) Use the holes in the Social Security Number. The SSN is composed of
3 parts, XXX-XX-XXXX, called the Area, Group, and Serial. The areas
are assigned as follows:
000 unused
627-699 unassigned, for future use
729-899 unassigned, for future use
900-999 not valid SSNs
3) invent a number if your state has privacy laws that require the SSN
not be used.|||Ed Prochak <ed.prochak@.magicinterface.com> wrote:

>Timothy J. Bruce wrote:
>[]
[vbcol=seagreen]
>That's rather poor advice. What posters should do is present as simple a
>sample of the problem as possible, including standard SQL. Mentioning the
>specific tools and environment used would be helpful.
I will second this most strenuously. Details help. For example,
sometimes, a problem is due to a bug with a particular version of a
particular DBMS. If a poster is going to make me guess about details
like this, I guess I will probably just move on to the next post.
[snip]
Sincerely,
Gene Wirchenko
Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Help with Many-to-Many-to-Many Problem

I am having a problem creating a many-to-many-to-many type relationship. It
works fine, but when I create a view to query it and test it, it does not
generate the results I expected.
Below if the DDL for the tables and the SQL for the view.
Any help would be most appreciated.
Many thanks in advance.
Regards
Keith
DIAGRAM 5: SYS_Relationship_Individuals_Courses
(http://www.step-online.org.uk/diagram5.png)
This is the relationship I am having a problem with. Each individual can
attend many courses. I have tried to model this by creating this diagram.
It has the following tables in it. SYS_Individual (to show individuals).
To show courses (which already have a many-to-many relationship
(http://www.step-online.org.uk/diagram2.png), I added all the same tables as
in diagram 2 - SYS_Courses, SYS_Courses_Venues, SYS_Courses_TimeTable,
SYS_Courses_Tutors (joined using SYS_Xref_Join_Courses). Now as each
individual could attend many courses, I assumed that the correct way to
model this would be by creating another many-to-many between the
SYS_Individual table and the SYS_Xref_Join_Courses by using a new join table
(SYS_Xref_Join_Ind_Courses).
I tried to check this works using a view (SYS_Individual_Courses_List) -
VIEW 5 below.
The problem is that no matter how many entries I put in the
SYS_Xref_Join_Ind_Courses, the test view (VIEW 5 below), only ever shows one
record. While playing around with the view, I got it to show all the
entries, but they were duplicated 4 times each! I can't remember how I did
this now either.
Now for the DDL for the tables:
CREATE TABLE [do].[SYS_Individual] (
[IND_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[IND_Date_Entered] [datetime] NOT NULL ,
[IND_Date_on_Project] [datetime] NULL ,
[IND_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Post_Code] [varchar] (10) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Telephone_Home] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Telephone_Mobile] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Telephone_Other] [varchar] (15) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Email_Address] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Date_Started] [datetime] NULL ,
[IND_Trading_Name] [varchar] (150) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Description_Proposed] [text] COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_Profile] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_DD_Economic_Activity_ID] [numeric](18, 0) NULL ,
[IND_DD_Referal_Source_Code] [numeric](18, 0) NULL ,
[IND_DD_Training_Status_ID] [numeric](18, 0) NULL ,
[IND_DD_Age_ID] [numeric](18, 0) NULL ,
[IND_DD_Potential_Business_Type_ID] [numeric](18, 0) NULL ,
[IND_DD_Exit_ID] [numeric](18, 0) NULL ,
[IND_DD_Disadvantage_ID] [numeric](18, 0) NULL ,
[IND_DD_Bank_ID] [numeric](18, 0) NULL ,
[IND_DD_Start_Up_Confirmation_ID] [numeric](18, 0) NULL ,
[IND_DD_Growth_Potential_ID] [numeric](18, 0) NULL ,
[IND_DD_Ethnicity_ID] [numeric](18, 0) NULL ,
[IND_DD_Marital_Status_ID] [numeric](18, 0) NULL ,
[IND_DD_Gender_ID] [numeric](18, 0) NULL ,
[IND_DD_Status_ID] [numeric](18, 0) NULL ,
[IND_Related_To_Another] [varchar] (3) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[IND_DD_Business_Status_ID] [numeric](18, 0) NULL ,
[IND_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Courses] (
[COURSE_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_Date_Entered] [datetime] NOT NULL ,
[COURSE_Title] [varchar] (255) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[COURSE_Description] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,
[COURSE_Last_Modified] [datetime] NULL
CREATE TABLE [dbo].[SYS_Courses_Venues] (
[COURSE_VEN_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_VEN_Date_Entered] [datetime] NOT NULL ,
[COURSE_VEN_Address] [text] COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL ,
[COURSE_VEN_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Courses_TimeTable] (
[COURSE_TT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_TT_Date_Entered] [datetime] NOT NULL ,
[COURSE_TT_Date] [datetime] NOT NULL
CREATE TABLE [dbo].[SYS_Courses_Tutors] (
[COURSE_TUT_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[COURSE_TUT_Date_Entered] [datetime] NOT NULL ,
[COURSE_TUT_First_Name] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[COURSE_TUT_Surname] [varchar] (30) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[COURSE_TUT_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Xref_Join_Courses] (
[XREF_Courses_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[XREF_Courses_Date_Entered] [datetime] NOT NULL ,
[COURSE_ID] [numeric](18, 0) NOT NULL ,
[COURSE_VEN_ID] [numeric](18, 0) NOT NULL ,
[COURSE_TT_ID] [numeric](18, 0) NOT NULL ,
[COURSE_TUT_ID] [numeric](18, 0) NOT NULL ,
[XREF_Courses_Last_Updated] [datetime] NULL
CREATE TABLE [dbo].[SYS_Xref_Join_Ind_Courses] (
[XREF_Ind_Course_ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[XREF_Ind_Course_Date_Entered] [datetime] NOT NULL ,
[IND_ID] [numeric](18, 0) NOT NULL ,
[XREF_Courses_ID] [numeric](18, 0) NOT NULL ,
[XREF_Ind_Course_Last_Updated] [datetime] NULL
Now for the View:
VIEW 5:
CREATE VIEW dbo.SYS_Individual_Course_List
AS
SELECT dbo.SYS_Individual.IND_First_Name,
dbo.SYS_Individual.IND_Surname, dbo.SYS_Courses.COURSE_Title,
dbo.SYS_Courses_Venues.COURSE_VEN_Address,
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID
FROM dbo.SYS_Courses_Venues INNER JOIN
dbo.SYS_Courses INNER JOIN
dbo.SYS_Xref_Join_Ind_Courses INNER JOIN
dbo.SYS_Individual ON
dbo.SYS_Xref_Join_Ind_Courses.IND_ID = dbo.SYS_Individual.IND_ID INNER JOIN
dbo.SYS_Xref_Join_Courses ON
dbo.SYS_Xref_Join_Ind_Courses.XREF_Ind_Course_ID = dbo.SYS_Xref_Join_Courses.XREF_Courses_ID ON
dbo.SYS_Courses.COURSE_ID = dbo.SYS_Xref_Join_Courses.COURSE_ID INNER JOIN
dbo.SYS_Courses_TimeTable ON
dbo.SYS_Xref_Join_Courses.COURSE_TT_ID = dbo.SYS_Courses_TimeTable.COURSE_TT_ID INNER JOIN
dbo.SYS_Courses_Tutors ON
dbo.SYS_Xref_Join_Courses.COURSE_TUT_ID = dbo.SYS_Courses_Tutors.COURSE_TUT_ID ON
dbo.SYS_Courses_Venues.COURSE_VEN_ID = dbo.SYS_Xref_Join_Courses.COURSE_VEN_IDKeith et al:
> I am having a problem creating a many-to-many-to-many type relationship.
It
In a single word: `No shit'. This is by design.
> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does
not
> generate the results I expected.
You should not have expected it to work in the First Place.
If you need to create a many-to-many relationship between relations A and
B, then we create a third relation C.
Intersect relations A and B with C (that is C accepts foreign keys from
relations A and B).
Since relation C should only contain the foreign key attributes from
relations A and B you should be able to figure out how to work with it.
Do not include DDL/source-code in usenet posts. People will try to
correct your code instead of your broken logic. For best results do not
even mention your `specific implementation'.
Have fun with your new `toy',
Timothy J. Bruce
uniblab@.hotmail.com
</RANT>|||"Keith" <@..> wrote in message
news:uzMhc.32757$h44.4860659@.stones.force9.net...
> I am having a problem creating a many-to-many-to-many type relationship.
It
> works fine, but when I create a view to query it and test it, it does not
> generate the results I expected.
>
> Below if the DDL for the tables and the SQL for the view.
>
> Any help would be most appreciated.
>
>
> Many thanks in advance.
>
> Regards
>
> Keith
>
<snip>
See the reply to your previous post - as Jacco suggested, it seems that you
are using inner joins where you should be using outer joins. I suggest you
check out the examples of outer joins in Books Online, so you can see how
they work using a simple example. Your solution will probably involve left
joins from SYS_Individual to the other tables.
Simon|||>> I am having a problem creating a many-to-many-to-many type
relationship. It
works fine, .. <<
No, you seem to have 5NF problems. You cannot create a true three-way
relationship as a series of binary relationships; look up join-project
normal forms.
But you have a lot of other problems.
1) Why did you make everything NUMERIC(18,0)? Think about what an
amazing thing that would be if reality was like that.
2) Why did you use IDENTITY instead of looking for real keys'
3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
lack of any industry standards for columns, etc.
4) Why put physical history into the tables? There are tools for
that.
5) Isn't a venue an attribute of a course?
6) What is the logical meaning of those XREF tables in terms of a
logical data model?
7) What is a "_type_id"' An attribute is either a type or it is an
identifier, but never both. Again, you don't understand the
differences between data and metadata, so you mix them in wreird ways.
Your DDL ought to look more like this:
CREATE TABLE IndividualCourses
(ssn CHAR(9) NOT NULL
REFERENCES Individuals (ssn)
ON UPDATE CASCADE
ON DELETE CASCADE,
course_id CHAR(5) NOT NULL)
REFERENCES Courses(course_id)
ON UPDATE CASCADE
ON DELETE CASCADE,
PRIMARY KEY (ssn, course_id));
You need constraints, defaults, real keys, logical names, etc. Start
over and get a book on data modeling.|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.com...
> >> I am having a problem creating a many-to-many-to-many type
> relationship. It
> works fine, .. <<
> No, you seem to have 5NF problems. You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.
> But you have a lot of other problems.
> 1) Why did you make everything NUMERIC(18,0)? Think about what an
> amazing thing that would be if reality was like that.
> 2) Why did you use IDENTITY instead of looking for real keys'
> 3) Why didn't you follow ISO-11179 naming rules? Terrible prefixes,
> lack of any industry standards for columns, etc.
> 4) Why put physical history into the tables? There are tools for
> that.
> 5) Isn't a venue an attribute of a course?
> 6) What is the logical meaning of those XREF tables in terms of a
> logical data model?
> 7) What is a "_type_id"' An attribute is either a type or it is an
> identifier, but never both. Again, you don't understand the
> differences between data and metadata, so you mix them in wreird ways.
> Your DDL ought to look more like this:
> CREATE TABLE IndividualCourses
> (ssn CHAR(9) NOT NULL
> REFERENCES Individuals (ssn)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> course_id CHAR(5) NOT NULL)
> REFERENCES Courses(course_id)
> ON UPDATE CASCADE
> ON DELETE CASCADE,
> PRIMARY KEY (ssn, course_id));
> You need constraints, defaults, real keys, logical names, etc. Start
> over and get a book on data modeling.
Just from curiosity - and I don't claim to have any answer to this question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not where
they were born.
Simon|||Timothy J. Bruce wrote:
[]
> Do not include DDL/source-code in usenet posts. People will try to
> correct your code instead of your broken logic. For best results do not
> even mention your `specific implementation'.
> Have fun with your new `toy',
> Timothy J. Bruce
> uniblab@.hotmail.com
> </RANT>
>
That's rather poor advice. What posters should do is present as simple a
sample of the problem as possible, including standard SQL. Mentioning the
specific tools and environment used would be helpful.
The related suggestion is that posters should post DBMS specific questions in
the specific area and general questions in the general area. IOW, they should
post on topic questions.
How many ORACLE or SQL SERVER specific questions have we seen here in the
generic comp.databases group? Too many. So the original poster on this thread
was misguided in his posting to both specific SQL SERVER groups and to the
comp.databases group. Such a posting is nearly always off topic in one or the
other group.
Since his question was about relations and not SQL SERVER syntax, the
generic databases group is more appropriate.
If replies are just picking apart syntax, then I would suggest they are off
topic in the comp.databases group (unless maybe they are pointing out
something is not Standard SQL).
Bottom line is:
1. post to the appropriate group (goes for both original and reply posting)
2. post as complete and succuint information as possible (including your
platform DB and OS) for the comp.databases group.
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost|||Simon Hayes wrote:
[]
> Just from curiosity - and I don't claim to have any answer to this question
> myself - what primary key would you use for European students? The SSN
> doesn't exist, and students routinely study in a country which is not where
> they were born.
> Simon
>
Don't use SSN, assign a unique student ID.
--
Ed Prochak
running http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost|||"--CELKO--" <joe.celko@.northface.edu> wrote in message
news:a264e7ea.0404231740.7f98d9d5@.posting.google.com...
> >> I am having a problem creating a many-to-many-to-many type
> relationship. It
> works fine, .. <<
>
You cannot create a true three-way
> relationship as a series of binary relationships; look up join-project
> normal forms.
>
Yes, you can- sometimes (often?). See
http://www.cis.drexel.edu/faculty/song/Papers/Jdb99.pdf|||>> Just from curiosity - and I don't claim to have any answer to this
question
myself - what primary key would you use for European students? The SSN
doesn't exist, and students routinely study in a country which is not
where they were born. <<
1) New York State used to make them get an SSN.
2) Use the holes in the Social Security Number. The SSN is composed of
3 parts, XXX-XX-XXXX, called the Area, Group, and Serial. The areas
are assigned as follows:
000 unused
627-699 unassigned, for future use
729-899 unassigned, for future use
900-999 not valid SSNs
3) invent a number if your state has privacy laws that require the SSN
not be used.|||Ed Prochak <ed.prochak@.magicinterface.com> wrote:
>Timothy J. Bruce wrote:
>[]
>> Do not include DDL/source-code in usenet posts. People will try to
>> correct your code instead of your broken logic. For best results do not
>> even mention your `specific implementation'.
>> Have fun with your new `toy',
>> Timothy J. Bruce
>> uniblab@.hotmail.com
>> </RANT>
>That's rather poor advice. What posters should do is present as simple a
>sample of the problem as possible, including standard SQL. Mentioning the
>specific tools and environment used would be helpful.
I will second this most strenuously. Details help. For example,
sometimes, a problem is due to a bug with a particular version of a
particular DBMS. If a poster is going to make me guess about details
like this, I guess I will probably just move on to the next post.
[snip]
Sincerely,
Gene Wirchenko
Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.|||joe.celko@.northface.edu (--CELKO--) wrote:
>> Just from curiosity - and I don't claim to have any answer to this
>question
>myself - what primary key would you use for European students? The SSN
>doesn't exist, and students routinely study in a country which is not
>where they were born. <<
>1) New York State used to make them get an SSN.
What do you do in the meantime for a PK? I--a Canadian--apply for
admission, and you will not admit me because I do not have an SSN? I
think I would want to take database courses elsewhere then!
>2) Use the holes in the Social Security Number. The SSN is composed of
>3 parts, XXX-XX-XXXX, called the Area, Group, and Serial. The areas
>are assigned as follows:
> 000 unused
> 627-699 unassigned, for future use
> 729-899 unassigned, for future use
> 900-999 not valid SSNs
And if the definition changes?
>3) invent a number if your state has privacy laws that require the SSN
>not be used.
I think #3 is best. 1) If your jurisdictions do not have privacy
laws, it does not mean that they never will. Some came into effect in
Canada this last New Year's Day. 2) If it is Their number, what do
you do if They change it or its definition?
Sincerely,
Gene Wirchenko
Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.