Storing ampersand in database

后端 未结 2 806
长情又很酷
长情又很酷 2021-01-23 09:26

I am currently working with an sql 2008 database. Many of the entries have ampersands stored thusly \'Arts & Culture\' Should we be storing the escaped version in the databa

相关标签:
2条回答
  • 2021-01-23 10:10

    Generally speaking, everything in a database should be stored as close to original version as possible. If you have to do any escaping, do it outside the DB.

    Reason for doing so is simple: it's only in web where you have to esape the & sign. If you will sometime have a non-web front-end to your DB, you will have to convert these escape sequences back to original value, which is not always possible: for example, if a user will enter & (sic), upon reconversion this will be translated back to &, which will lose original meaning.

    0 讨论(0)
  • 2021-01-23 10:22

    SQL Server will store Arts & Culture just fine, into either a VARCHAR(x) or a NVARCHAR(x) (Unicode-variant - 2 bytes per character) field.

    From a database point of view, there's absolutely no need or no point in escaping anything.

    0 讨论(0)
提交回复
热议问题