SQL Server表设计用于短链接 [英] SQL Server table design for short links

查看:90
本文介绍了SQL Server表设计用于短链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用ASP.NET和SQL Server开发缩短链接的网站

缩短的网址应该看起来像http://domain.com/s0hg12j

这意味着每个链接都有一个唯一的字母数字代码,用于标识该链接,并将从链接表中检索它。

我的问题是:

我应该制作字母数字代码链接表的主键或创建一个int identity主键并将该字母数字列作为唯一索引?

I will develop shorten link website using ASP.NET and SQL Server
The shorten url should look like http://domain.com/s0hg12j
That means that every link will have a unique alphanumeric code that identify that link and will be the way to retrieve it from the links table
My question is:
should I make that alphanumeric code the primary key for the links table or make an int identity primary key and make that alphanumeric column as unique index?

推荐答案

我个人喜欢使用两个代理键作为主键和自然键(或键)作为唯一约束。



好​​处是密钥没有任何意义所以总是使用表之间的连接来获取实际数据,并且实际数据不是全部分散在数据库中,因为如果它用作外键。这使得更新数据更加简单。
Personally I like to use both surrogate key as a primary key and a natural key (or keys) as unique constraints.

The benefit is that the key means nothing so the actual data is always fetched using joins between tables and the actual data isn't scattered all araund the database because if it is used as a foreign key. This makes updating the data much more simpler.


这篇关于SQL Server表设计用于短链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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