我看到一个 SP,其中身份函数的调用方式如下:
select id = identity(10) ..... into ..... from ......
如果我只能传递 1 个或 2 个参数而不是三个参数(SEED、INCREMENT、数据类型),谁能告诉我吗?
另外如果表中的一列已经被定义为identity,是不是意味着它会自动生成一个唯一的序号?那么这个 identity() 函数究竟需要什么?
最佳答案
Sybase 12.0.1 文档 here说:
IDENTITY function [Miscellaneous]
Generates integer values, starting at 1, for each successive row in a query. Its implementation is identical to that of the NUMBER function.
Syntax
IDENTITY( expression ) Parameters
• expression An expression. The expression is parsed, but is ignored during the execution of the function.
Returns
INT
Remarks
The description of the IDENTITY function is the same as the description of the NUMBER function.
See also
•NUMBER function [Miscellaneous]
Standards and compatibility
• SQL/2008 Vendor extension.
Example
The following statement returns a sequentially-numbered list of employees.
SELECT IDENTITY( 10 ), Surname FROM Employees;
与 MS SQL Server 不同,Sybase 只处理一个参数。种子和增量始终为 1。
如果所选数据中有任何标识列,则将复制它们的值。 IDENTITY
函数允许您在输出表中创建一个新的标识列。
关于tsql - SQL 中的 IDENTITY() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16586805/