SQL Server规范化策略:varchar vs int Identity [英] SQL Server normalization tactic: varchar vs int Identity

查看:167
本文介绍了SQL Server规范化策略:varchar vs int Identity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道这里的最佳解决方案。

I'm just wondering what the optimal solution is here.

说我有一个标准化的数据库。整个系统的主要关键是varchar。我想知道的是,我应该将这个varchar与一个int进行归一化还是关闭?离开一个varchar更简单,但它可能更优化

Say I have a normalized database. The primary key of the whole system is a varchar. What I'm wondering is should I relate this varchar to an int for normalization or leave it? It's simpler to leave as a varchar, but it might be more optimal

例如我可以有

People
======================
name      varchar(10)   
DoB       DateTime    
Height    int  

Phone_Number
======================
name      varchar(10)   
number    varchar(15)

或者我可以有

People
======================
id        int Identity   
name      varchar(10)   
DoB       DateTime  
Height    int  

Phone_Number
======================
id        int   
number    varchar(15)  

当然可以添加其他一对多关系。

Add several other one-to-many relationships of course.

你们都想什么?哪个更好,为什么?

What do you all think? Which is better and why?

推荐答案

你真的可以使用名字作为主键吗?是否有几个同名的人的风险很高?

Can you really use names as primary keys? Isn't there a high risk of several people with the same name?

如果你真的很幸运,你的姓名属性可以用作主键,那么 - 通过一切手段 - 使用它。通常情况下,您将不得不做一些事情,例如customer_id等。

If you really are so lucky that your name attribute can be used as primary key, then - by all means - use that. Often, though, you will have to make something up, like a customer_id, etc.

最后:NAME是至少一个DBMS中的保留字,因此考虑使用别的东西,例如全名。

And finally: "NAME" is a reserved word in at least one DBMS, so consider using something else, e.g. fullname.

这篇关于SQL Server规范化策略:varchar vs int Identity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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