URL 的最佳列类型是什么? [英] What is the best column type for URL?

查看:31
本文介绍了URL 的最佳列类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server 的 URL 字段的最佳列类型是什么?

What is the best column type for a URL field for SQL Server?

类型:VARCHAR 还是 NVARCHAR?

Type: VARCHAR or NVARCHAR?

长度?

类似的 MySQL 问题.

推荐答案

如果您准备在存储 URL 之前始终对其进行 URL 编码(Google 提供的示例是 中.doc URL 编码为 %E4%B8%AD.doc) 那么你可以安全地坚持使用 varchar.如果您希望 URL 中的非 ASCII 字符在数据库中保持可读,那么我建议使用 nvarchar.如果你不想被抓到,那就去 nvarchar.

If you are prepared to always URL encode your URLs before you store them (an example turned up by Google was 中.doc URL encoding to %E4%B8%AD.doc) then you are safe sticking with varchar. If you want the non-ASCII characters in your URLs to remain readable in the database then I'd recommend nvarchar. If you don't want to be caught out, then go for nvarchar.

由于 IE(最严格的主流浏览器)不支持长度超过 2083 个字符的 URL,那么(除了您可能对索引或行长度的任何考虑),您可以使用 nvarchar(2083) 涵盖最有用的场景).

Since IE (the most restrictive of the mainstream browsers) doesn't support URLs longer than 2083 characters, then (apart from any considerations you might have on indexing or row length), you can cover most useful scenarios with nvarchar(2083).

这篇关于URL 的最佳列类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆