主键选择问题 [英] Primary Key Selection Problem

查看:72
本文介绍了主键选择问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个员工信息数据库.我通常为每个表保留一个自动递增的ID主键.但是,还有一个唯一的employeeID字段.现在的问题是我想知道选择自动递增的主键更好还是选择varchar,用户将提供输入?此主键已在许多其他表中用作外键.我正在使用严重的MSSQL2008.请帮助...

I am designing a employee information database. I usually keep an auto incremented ID primary key for each table. But there is also a unique employeeID field. Now problem is i want to know choosing a auto incremented primary key is better or choosing a varchar , that the user will give input? This primary key has been used as foreign key in many other tables. I am using MSSQL severe 2008. Please help......

推荐答案

自动增量主键更好(搜索int比搜索varchar更快).该键可以与FK和索引一起在其他表中使用.
自动增量知道如何保持id唯一.
autoincrement primary key is better (searching for int is faster than searching for a varchar). This key can be used in other tables in combination with FK and index.
The autoincrement knows how to keep the id unique.


使用整数列作为键.它不应该是用户输入.只是出于好奇,用户为什么要为EmployeeId提供输入?
Use a integer column as a key. It should not be a user input. Just because of curiosity, why would user provide input for EmployeeId?


这篇关于主键选择问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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