How do I link the File Table with my existing table in SQL server

Viewed 2189

I have a requirement of saving employees image in database. I have been asked to use File Tables. After googling on this I got some fine contents as to how to get started with File Tables. And I managed to create them, also inserting data to these tables is as simple as copy/paste to specified folder and the data gets inserted into the table. The problem is how do I relate each employee row set with their respective imagesSample row data from the Filetable

The overall flow will be like the employee will upload his/her image or doc through front end, which will save the image on the server. the problem is how to add reference of employee with its respective image. One option can be having a FileName column in the employee table which refers to the name column in the FileTable, but I need something more efficient such as relating the id's. Any other way of achieving this would be appreciated.

3 Answers

Wouldn't just having a "joining (many-to-many) table" in between employer and the filetable be just as easy? You wouldn't have to use it as a many-to-many table. Call it EmployeeImages and add a description attribute/property i.e "Hiring photo", "Just got fired photo". with both primary keys from employee and filetable. simples!

You have to insert in your program the code for copying file. File.Copy(...) Instead of just copying and pasting into file system. So that, each instance that your File.Copy executes, you can get its respective stream_id, which then you attach on your employees table..

Related