Database design : preferred field length for file paths

前端 未结 7 1013
南笙
南笙 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:37

    If your using SQL Server, it's good to know that Microsoft is using nvarchar(260) fields to store file path and name in the system tables (like sys.database_files, or sys.sysaltfiles, or sys.master_files).

    Column name      Data type        Description
    -------------    -------------    ---------------------------
    physical_name    nvarchar(260)    Operating-system file name.
    

    Good practice could be to use the same format to store your path and file name.

    You will, of course, need to enforce the size in your UI to be sure that it will not be truncated during INSERT or UPDATE.

提交回复
热议问题