简体   繁体   English

SQL Server身份种子

[英]SQL Server Identity Seed

I have a SQL Servier database where I store schedules for multiple companies in a table called tblSchedules. 我有一个SQL Servier数据库,在其中将多个公司的日程表存储在名为tblSchedules的表中。

The primary key for this table is ScheduleRatesID and auto increments. 该表的主键是ScheduleRatesID和自动增量。

Is there a way to have is increment from 700000 for Company A and 800000 for Company B? 有没有办法从A公司的700000和B公司的800000递增?

您可以将它们放入两个不同的表中,然后使用视图将它们结合在一起...恐怕这是您唯一的选择。

我的建议是删除此表上的自动增量,并创建一个触发器来检查companyid,并且必须基于companyid计算并在指定的两个不同范围之间插入一个唯一的主键。

No. Identity does not work that way. 不能。身份不能那样工作。

Sit down and write your own mechanism - it is not particularly hard. 坐下来并编写自己的机制-并不是特别困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM