With (nolock)


I want to use SELECT query with WITH (NOLOCK) like:
SELECT “dbo”.“table_name”.“Country” AS “Country” WITH (NOLOCK)
when I run it got this error:
“com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword ‘with’. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.”

Is it possible can I use “WITH (NOLOCK)” i native qurey?


Hi @shadlou
You will probably find better help on stackoverflow.com or a forum specific for SQL Server.
It seems like everyone - even Microsoft - is recommending not to use NOLOCK:
But the solution seems to be not use WITH (NOLOCK), but simply setting a global variable to enable the same functionality on all tables:

You’re missing the FROM clause, nothing to do with NOLOCK.

SELECT “dbo”.“table_name”.“Country” AS “Country” **FROM table_name** WITH (NOLOCK)

Discussion on whether or not NOLOCK should be used is for another time.

Thanks @AndrewMBaines, It has been solved.