April 18, 2020 at 11:54 pm
I have two tables; a path table that contains distinct paths and a node table that contains distinct nodes. A node can be present in one or more paths. A path is composed of one or more nodes (the path is composed of the id of the nodes concatenated by a dot). The image below shows an example of these tables:
I want to create the entity-relationship diagram, but I am confused about what to do in cardinalities.
Is the diagram below correct?
Thank you in advance
April 19, 2020 at 11:16 pm
Heh... Ok... I'll bite. Is it? 😉
I also wonder why people do this type of thing to perfectly good relational data.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 22, 2020 at 10:24 pm
I do this in order to store an XML path
April 22, 2020 at 11:43 pm
The usual way to model this structure is like this:
IF OBJECT_ID('Path','U') IS NOT NULL DROP TABLE Path
IF OBJECT_ID('Node','U') IS NOT NULL DROP TABLE Node
GO
CREATE TABLE Node
(
NodeId int IDENTITY(1, 1) NOT NULL PRIMARY KEY CLUSTERED,
Name varchar(20)
);
GO
CREATE TABLE Path
(
PathNumber int NOT NULL,
NodePosition int NOT NULL,
NodeId int NOT NULL,
CONSTRAINT PK_Path PRIMARY KEY CLUSTERED (PathNumber, NodePosition),
CONSTRAINT FK_Path_Node FOREIGN KEY (NodeId) REFERENCES Node (NodeId)
)
GO
INSERT INTO Node(Name)
VALUES ('books'),
('book'),
('author'),
('title')
GO
INSERT INTO Path(PathNumber,NodePosition,NodeId)
VALUES (1, 1, 1),
(2, 1, 1),
(2, 2, 2),
(3, 1, 1),
(3, 2, 2),
(3, 3, 3),
(4, 1, 1),
(4, 2, 2),
(4, 3, 3),
(4, 4, 4)
SELECT p.PathNumber,
p.NodeId
FROM Path p
INNER JOIN Node n
ON n.NodeId = p.NodeId
ORDER BY p.PathNumber, p.NodePosition
See the foreign key for how to get entity relationship.
April 23, 2020 at 4:56 pm
I do this in order to store an XML path
To be honest, that sounds like a slow and possibly error prone process being made to be slower and more resource intensive.
But, before I go into any of that, I have a couple of questions...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply