如果主键总是从1开始? [英] Should primary key always start from 1?

查看:131
本文介绍了如果主键总是从1开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我迁移旧的数据库(Oracle)和有像国家code 部code <几桌/ code>和角色codeS ,其主键是字符串( codeS )和我正在考虑将数列作为主键,因为它将与加入工作速度快。这些表是不是真的大了。

I am migrating an old database (oracle) and there are few tables like CountryCode, DeptCode and RoleCodes, their primary key is string (Codes) and i am thinking about adding Number column as a primary key because it would work fast with joins. These tables are not really big.

我想知道如果这些表的主键应该从数量开始'1',也可以从100开始只是分化的B / W表PK,虽然我不认为我会展示他们的报告。

I am wondering if primary key for those tables should start from number '1' or it can be started from 100 just to differentiate b/w tables PK although i don't think i would be showing them on reports.

推荐答案

有关生成序列的ID,我的将会的不同值建议首先,如果它很容易做到(取决于您的数据库等上)。你不应该使用这种在code 的他们的区分,但它可以使测试更加合理。

For sequence-generated IDs, I would suggest starting at different values if it's easy to do (depends on your database etc). You shouldn't be using this to differentiate between them in code, but it can make testing more reasonable.

在此之前,我有一个情况我不小心使用外键一个表中的,如果的它是另一个表的外键。作为标识传递的测试是的巧合的是的相同。之后,我们发现了这个问题,我们改变了最初的种子,结果发现测试是一个的很多的清晰。

Before now, I've had a situation where I've accidentally used a foreign key one table as if it were the foreign key for another table. The tests passed as the IDs were coincidentally the same. After we discovered the problem, we changed the initial seed and found the tests were a lot clearer.

这篇关于如果主键总是从1开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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