Jeremiah Jeschke
Jeremiah Jeschke

Reputation: 107

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]).

Upvotes: 0

Views: 170

Answers (2)

Joe Stefanelli
Joe Stefanelli

Reputation: 135848

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.

Upvotes: 4

Rahul Tripathi
Rahul Tripathi

Reputation: 172548

Try this:

DELETE FROM [table] WHERE [index] = 1

as index is a reserved keyword in Sql Server.

Upvotes: 0

Related Questions