I have a relatively unusual requirement. I will simplify it as much as possible. I have files, each of which references (includes) 0-n other files. For example:
For example if file1 references (includes):
- file2
- file3
- file2
- file3
- 1 file1
- 2 file2
- 3 file3
- 4 file4
- 1 2
- 1 3
- 4 2
- 4 3
Code: Select all
CREATE TABLE [dbo].[files] (
[Id] INT AUTO_INCREMENT NOT NULL,
[Filename] NVARCHAR (100) NOT NULL,
PRIMARY KEY ([Id] ASC)
);
Code: Select all
CREATE TABLE [dbo].[includes] (
[IncludingId] INT NOT NULL,
[IncludedId] INT NOT NULL,
PRIMARY KEY ([IncludingId],[IncludedId] ASC),
CONSTRAINT FK_Including FOREIGN KEY (IncludingId)
REFERENCES files(Id),
CONSTRAINT FK_Included FOREIGN KEY (IncludedId)
REFERENCES files(Id)
);
I have tried using the Open Office GUI to create the foreign keys but they were not saved when I saved the changes. So my next attempt will be to put the SQL into MySQL.
Is my database model too complicated for my purposes? I understand about self-referencing recursive tables. I think I can't do that since the children (included / referenced) files can be children of other files too.