(1,1) 在 SQL 中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34965970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does (1,1) mean in SQL?
提问by xarzu
What does (1,1) mean in SQL? I mean in the following context:
(1,1) 在 SQL 中是什么意思?我的意思是在以下上下文中:
create table PetOwner
(
Id int identity(1,1)
, Name nvarchar(200)
, Policy varchar(40)
)
回答by itzmebibin
In Id int identity(1,1)
, the first 1 means the starting value of ID and the second 1 means the increment value of ID. It will increment like 1,2,3,4.. If it was (5,2), then, it starts from 5 and increment by 2 like, 5,7,9,11,...
在 中Id int identity(1,1)
,第一个 1 表示 ID 的起始值,第二个 1 表示 ID 的增量值。它将像 1,2,3,4.. 一样递增。如果它是 (5,2),那么它从 5 开始并以 2 递增,例如,5,7,9,11,...
回答by Lukasz Szozda
SQL Server
IDENTITY
column:
SQL Server
IDENTITY
柱子:
IDENTITY [ (seed , increment) ]
Identity columns can be used for generating key values. The identity property on a column guarantees the following:
Each new value is generated based on the current seed & increment.
Each new value for a particular transaction is different from other concurrent transactions on the table.
身份 [(种子,增量)]
标识列可用于生成键值。列上的标识属性保证以下内容:
每个新值都是根据当前种子和增量生成的。
特定事务的每个新值都不同于表上的其他并发事务。
Start from 1 with step 1.
从第 1 步开始。
Very convenient way to generate "consecutive" numbers. Please note that:
生成“连续”数字的非常方便的方法。请注意:
Reuse of values – For a given identity property with specific seed/increment, the identity values are not reused by the engine. If a particular insert statement fails or if the insert statement is rolled back then the consumed identity values are lost and will not be generated again. This can result in gaps when the subsequent identity values are generated.
值的重用——对于具有特定种子/增量的给定身份属性,引擎不会重用身份值。如果特定的插入语句失败或插入语句被回滚,则使用的标识值将丢失并且不会再次生成。这可能会导致生成后续标识值时出现间隙。
create table #PetOwner(
Id int identity(1,1)
, Name nvarchar(200)
, Policy varchar(40));
INSERT INTO #petOwner(Name, Policy)
VALUES ('Tim', 'a'),('Bob' ,'b');
SELECT *
FROM #PetOwner;