Search code examples
sqlsql-serversql-server-ce

How to delete a row in SQL Server via Identity?


What's the proper syntax for a row delete via an identity column? The query:

    "DELETE FROM [table] WHERE [column 'count'] = 1"

works. While the same query where the identity column is 'index' fails.

    "DELETE FROM [table] WHERE index = 1"

I'm trying to delete the last inserted row with IDENT_CURRENT([table]).


Solution

  • Index is a reserved word. You have to escape it with square brackets.

    DELETE FROM [table] WHERE [index] = 1
    

    And be sure to give a special "thanks" to whoever designed the schema with that column name in the first place.