Database design : preferred field length for file paths

前端 未结 7 939
南笙
南笙 2021-01-04 02:49

I have to store file paths in a DB field (/tmp/aaa/bbb, C:\\temp\\xxx\\yyy, etc.). I can\'t really tell how long they could be.

Given this

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 03:42

    I suggest you do not store the paths in your existing table. Create a new table having a sequential counter as the clustered primary key and a character column of the maximum length of your db program. I use SQL Server so I would use varchar(max).

    Create a column in your data table to hold the primary key of the "paths" table. Insert into the "paths" table first then use the primary key as the foreign key back in your data table.

    The advantage of storing the value in another table is it does not influence the data size of the base table. Queries of the base table which do not involve the "paths" do not suffer from having to pull in a large character value which increases the IO traffic.

提交回复
热议问题