查看identity列的值是否小于某个数字

时间:2013-06-05 19:02:16

标签: sql sql-server sql-server-2008

我试图查看标识列的值是否小于1.

IF (SELECT PKIdent FROM dbo.MyTable WHERE PKIdent < 1)
PRINT 'Its less than one'

1 个答案:

答案 0 :(得分:1)

以下两种方法可以做到这一点:

IF ((SELECT min(PKIdent) FROM dbo.MyTable) < 1)
    PRINT 'Its less than one'

IF exists (SELECT PKIdent FROM dbo.MyTable WHERE PKIdent < 1)
    PRINT 'Its less than one'