一个 sql server 表可以有两个标识列吗? [英] Can a sql server table have two identity columns?

查看:31
本文介绍了一个 sql server 表可以有两个标识列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一列作为主键,另一列用于自动增加订单号字段.这可能吗?

I need to have one column as the primary key and another to auto increment an order number field. Is this possible?

我想我会使用一个复合数作为订单号.还是谢谢.

I think I'll just use a composite number as the order number. Thanks anyways.

推荐答案

CREATE TABLE [dbo].[Foo](
    [FooId] [int] IDENTITY(1,1) NOT NULL,
    [BarId] [int] IDENTITY(1,1) NOT NULL
)

返回

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

所以,不,您不能有两个标识列.您当然可以使主键不自动递增(身份).

So, no, you can't have two identity columns. You can of course make the primary key not auto increment (identity).

msdn:CREATE TABLE (Transact-SQL)创建表 (SQL Server 2000):

每个表只能创建一个标识列.

Only one identity column can be created per table.

这篇关于一个 sql server 表可以有两个标识列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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