I have a table that contains file paths, like so:
--------------------
|Files |
--------------------
|path nvarchar(500)|
--------------------
I want to split it into two tables, one containing unique directories and one containing filenames:
---------------------------
|Files |
---------------------------
|filename nvarchar(255)|
|directoryId int |
---------------------------
---------------------------
|Directories |
---------------------------
|id int |
|path nvarchar(255)|
---------------------------
So for example if an entry originally was "C:/folder/file.jpg", I want an entry in Directories for "C:/folder/", and the entry in Files would be updated to have "file.jpg" for the filename and the directory id of the new entry in Directories.
(In case you're wondering at this point, the reason I need to do this is because I need to keep track of some information at the directory level.)
Is there a good way to do this in a T SQL script?