0

I want to store a file structure similar to Google Drive. I can create files of several types (doc, spreadsheet, ..). Details of each file are stored in their table.

For example:

File [id, name, file_id]
Doc [file_id, title, a, b, c]
Spreadsheet [file_id, title, d, e]

How to do it right?

Anton
  • 23
  • 1
  • 3
  • Based on the structure you provided, you can use 2 tables: FileType[Id, Name] File[Id, FileTypeId, Title, FileData ] – Eugene Sep 27 '18 at 20:14
  • Yes, but I need different attributes for each FileType. – Anton Sep 27 '18 at 21:09
  • So what's the problem with this structure ? – Eugene Sep 27 '18 at 21:15
  • From the question it seems that you want to reference with the foreign key from File to Doc/Spreadsheet. If that's the case the solution would be to declar file_id in Doc and Spreadsheet as Primary Key as well as Foreign Key that references to the File table. – tsp Sep 27 '18 at 21:34

2 Answers2

0

File

[id, name, file_id]

Doc_type Which ends up being a category list table

[file_id, title, extension,]

And then in Doc_type for example:

|file_id | title | extension|
|0001    | Word  | DOCX     |
|0002    | Excel | XLSX     |
DeFlanko
  • 66
  • 8
0

That is not how foreign keys work. You need File.id to be the primary key and then you would add File.id to each of the other tables and have each of them have a foreign key to File.id. In a practical sense create a File instance and then create either a Doc or a Spreadsheet and link it to the File instance.

BrianR
  • 9
  • 2