Mike Cole
Mike Cole

Reputation: 14713

Storing special characters in database

Can somebody provide some best practices when storing special characters such as the trademark (tm or r) or copyright (c)? I am storing them in a varchar field with other text in SQL Server, and displaying on an ASP.NET webpage. Right now we are storing the special character itself and displaying that.

Thanks for any help!

Upvotes: 2

Views: 4440

Answers (4)

hawkip
hawkip

Reputation: 154

This in an old question but it deserves a new answer: use UTF-8. Browsers, databases and web servers now all support UTF-8 encoding which means that you don't have to encode special characters (except as discussed here, and then, only on the way out).

There are some excellent reasons not to encode data in your database in this answer.

Upvotes: 0

RickNZ
RickNZ

Reputation: 18654

Just use the HTML entities, such as ™ and © if you can.

There's no need to switch to nvarchar unless you have an explicit requirement to support Unicode.

Upvotes: -1

Noon Silk
Noon Silk

Reputation: 55082

Well, with those characters, generally you will render them as

©

So you don't need to do anything special in the DB, but you should be using the "N"-prefixed fields for DB strings, NChar, NVarChar, and so on.

Upvotes: 2

Joel Coehoorn
Joel Coehoorn

Reputation: 415735

I am storing them in a varchar field ...

There's one problem, at least. For text that could have "special" characters, you need nvarchar.

Upvotes: 3

Related Questions