问题描述
我在SQL Server 2008 R2中创建了一个新表,我希望索引是自动递增的.怎么做?没有身份数据类型;我选择了诠释
I created a new table in SQL Server 2008 R2, and i would like that the index is on autoincrement.How to do that? There is no identity data type; i selected int
推荐答案
在SQL Server中,它不是单独的数据类型(自动增量")-但您可以将INT
列定义为IDENTITY
.
In SQL Server, it's not a separate datatype ("autoincrement") - but you can define an INT
column to be an IDENTITY
.
如何创建表-可视设计器或T-SQL脚本?
How are you creating your table - visual designer or T-SQL script??
在T-SQL中,您将使用:
In T-SQL, you would use:
CREATE TABLE dbo.MyTable(ID INT IDENTITY(1,1) ......
在可视表设计器中,您需要检查:
and in the visual table designer, you need to check:
这是INT类型的列的选项-您可以定义种子(起始值)和增量-通常都设置为1.
It's an option for a column of type INT - you can define the seed (starting value) and the increment - typically both are set to 1.
这篇关于Microsoft SQL Server 2008 R2的索引自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!