简体   繁体   English

查询在SQL Server CE中创建自动增量列,C#

[英]Query for creating a auto increment column in SQL Server CE, C#

What is the query in SQL Server CE to create a column that is auto-increment? SQL Server CE中的查询是什么创建自动增量的列?

Tried with IDENTITY(1,1), PRIMARY KEY .. No luck yet :( 试过IDENTITY(1,1), PRIMARY KEY ..还没有运气:(

Please guide me, thanks in advance ! 请指导我,提前谢谢!

From the documentation : 文档

CREATE TABLE MyCustomers 
    (
      CustID int IDENTITY (100,1) PRIMARY KEY
     ,CompanyName nvarchar (50)
    )

I think your issue is the ',' after the identity clause - remove it and it should work. 我认为你的问题是','在身份条款之后 - 删除它,它应该工作。

If you tried with 如果你试过

IDENTITY(1,1), PRIMARY KEY

try dropping the comma: 尝试删除逗号:

IDENTITY(1,1) PRIMARY KEY

Also, please note that: 此外,请注意:

  • a table can have at most one identity column 一个表最多只能有一个标识列
  • you can specify PRIMARY KEY on a column the first time you create the table. 您可以在第一次创建表时在列上指定PRIMARY KEY If you are doing an ALTER TABLE [...] ADD COLUMN , this is invalid 如果您正在执行ALTER TABLE [...] ADD COLUMN ,则此操作无效

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

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