Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / July 2005



Tip: Looking for answers? Try searching our database.

Q: Table within a table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Geoff Jones - 27 Jul 2005 16:01 GMT
Hi

Can anybody help me out with a problem? Is it possible to have a table which
has other tables as entries? For example, suppose the main table is called
table1. It contains two fields, a primary key field and another which
contains tables. The tables in these fields, also only have two fields BUT
the difference is that they will have a different number of rows.

Maybe this will give a better idea of what I mean:

ID         tables
==       =====

0            tableA
1            tableB
2            tableC

tableA has 5 rows
tableB has 2 rows
tableC has 20 rows

Does anybody have an idea of how to do this sort of thing?

Geoff
Andrea Montanari - 28 Jul 2005 15:17 GMT
hi Geoff,
> Hi
>
[quoted text clipped - 20 lines]
>
> Geoff

the relational model does not imply this model.. and implemets this design
using related tables where the detail table references the master table in
it's primary key, in a one to many design... that's to say
SET NOCOUNT ON
USE tempdb
GO
CREATE TABLE dbo.Master (
ID int PRIMARY KEY
)
CREATE TABLE dbo.Detail (
ID int PRIMARY KEY ,
IdParent int NOT NULL
 CONSTRAINT fk_Master_detail
  FOREIGN KEY
  REFERENCES dbo.Master (ID),
Data varchar(5)
)
INSERT INTO dbo.Master VALUES ( 0 )
INSERT INTO dbo.Master VALUES ( 1 )
INSERT INTO dbo.Master VALUES ( 2 )

INSERT INTO dbo.Detail VALUES ( 1 , 0 ,'a' )
INSERT INTO dbo.Detail VALUES ( 2 , 0 ,'b' )
INSERT INTO dbo.Detail VALUES ( 3 , 0 ,'c' )

INSERT INTO dbo.Detail VALUES ( 4 , 1 ,'a' )
INSERT INTO dbo.Detail VALUES ( 5 , 1 ,'b' )

INSERT INTO dbo.Detail VALUES ( 6 , 2 ,'a' )

SELECT m.ID , d.ID, d.Data
FROM dbo.Master m
 JOIN dbo.Detail d
 ON d.IdParent = m.ID

DROP TABLE dbo.Detail , dbo.Master

an attribute can not be of a table type, as the desing would suffer from not
adhering to properties of a tuple, where every tuple contains exactely 1
value for each of it's attributes and also would violate normal forms
design..
the upper normalization can be however rebuilt in your design using the Data
Shaping Service for OLE DB, which supports hyearachical rowsets in VB6
and/or COM implementation,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dtsprog/dtsptas
ks_8jqh.asp
,
where the .Net framework include a new model, the DataSet, supporting
DataTable bound in DataRelation as well...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fSystemDataDataSetClassTopic.asp

Signature

Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm        http://italy.mvps.org
DbaMgr2k ver 0.14.0  -  DbaMgr ver 0.59.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.