tsql - SQL 中的 IDENTITY() 函数

标签 tsql sybase

我看到一个 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/

相关文章:

sql - 如何在 Sql Server 和过滤器记录中对集合进行分组

PHP Exec 不工作,但命令本身工作正常

java - 如何告诉 Hibernate 注解 @Column 区分大小写?

paging - 如何在不创建临时表的情况下在 Sybase 中进行分页? (oracle rownum 问题)

sql - 每一行都调用1 = 2的地方吗?

python - sqlalchemy:bindparam 和 exec proc 在文本中不起作用

sql - 是否可以计算 group by 中一列的总和?

sql - 我如何先由 parent 订购,然后由 child 订购?

SQL Server,在 SQL 中创建临时表时出现问题

sql - 如何一次性删除SQL Server数据库中的所有存储过程?