加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

如何自动递增非主键? – SQL Server

发布时间:2020-12-12 08:48:35 所属栏目:MsSql教程 来源:网络整理
导读:CREATE TABLE SupplierQuote(supplierQuoteID int identity (3504,2) CONSTRAINT supquoteid_pk PRIMARY KEY,PONumber int identity (9553,20) NOT NULL...CONSTRAINT ponumber_uq UNIQUE(PONumber)); 以上ddl产生错误: Msg 2744,Level 16,State 2,Line 1 M
CREATE TABLE SupplierQuote
(
supplierQuoteID int identity (3504,2) CONSTRAINT supquoteid_pk PRIMARY KEY,PONumber int identity (9553,20) NOT NULL
.
.
.
CONSTRAINT ponumber_uq UNIQUE(PONumber)
);

以上ddl产生错误:

Msg 2744,Level 16,State 2,Line 1
Multiple identity columns specified
for table ‘SupplierQuote’. Only one
identity column per table is allowed.

我该如何解决?我想要PONumber自动递增.

解决方法

每个表不能有多个标识列.我认为你最好的选择是将PO数据拉到一个单独的表格中,然后将两者与FK列相关联.
SupplierQuote
-------------
supplierQuoteID (PK/identity)
purchaSEOrderID (FK to PurchaSEOrder.purchaSEOrderID)
otherColumn1

PurchaSEOrder
-------------
purchaSEOrderID (PK/identity)
otherColumn1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读