With (nolock)

Hi,

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?

Regards

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:
https://stackoverflow.com/questions/686724/what-is-with-nolock-in-sql-server
https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-2017
But the solution seems to be not use WITH (NOLOCK), but simply setting a global variable to enable the same functionality on all tables:
https://docs.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-2017

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.