July 16, 2013 at 1:13 pm
hi
select * from tableA with(nolock) a
join tableB with(nolock) b
on a.id = b.id
where a.date > getdate()
i am getting error incorrect syntax near a
July 16, 2013 at 1:35 pm
To correct the error, put the alias befor the WITH
select * from tableA a with(nolock)
join tableB b with(nolock)
on a.id = b.id
where a.date > getdate()
You should as well be aware that NOLOCK might give you wrong results.
Check these links
SQL Server NOLOCK Hint & other poor ideas.
July 16, 2013 at 1:36 pm
Try the following:
select * from tableA a with(nolock)
join tableB b with(nolock)
on a.id = b.id
where a.date > getdate()
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
July 16, 2013 at 1:41 pm
Or you could just remove the nolock hints entirely and remove any chance of their nasty side effects causing you problems.
See - http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 16, 2013 at 4:22 pm
riya_dave (7/16/2013)
hiselect * from tableA with(nolock) a
join tableB with(nolock) b
on a.id = b.id
where a.date > getdate()
i am getting error incorrect syntax near a
As Gail said, why nolocks?
Also alias names for tables either follow the table name itself or the word 'as', nothing else.
July 17, 2013 at 1:18 am
Voide (7/16/2013)
riya_dave (7/16/2013)
hiselect * from tableA with(nolock) a
join tableB with(nolock) b
on a.id = b.id
where a.date > getdate()
i am getting error incorrect syntax near a
As Gail said, why nolocks?
Also alias names for tables either follow the table name itself or the word 'as', nothing else.
Because, if you use NOLOCK then there is a chance of get inappropriate data...
Suppose you have opened a transaction and made some changes to the table and didn't Commit the transaction... After that you are using SELECT statement using NOLOCK option then you will get the modified data as the transaction was not committed... Then you ROLLBACK the transaction and again run the SELECT statement with NOLOCK then you will get your previous data...
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 17, 2013 at 1:27 am
GilaMonster (7/16/2013)
Or you could just remove the nolock hints entirely and remove any chance of their nasty side effects causing you problems.See - http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx
Gail,
Can you please tell me that when we have to use NOLOCK option as it gives us inappropriate data in result?
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 17, 2013 at 1:45 am
Can you please tell me that when we have to use NOLOCK option as it gives us inappropriate data in result?
You don't have to use it. There's no situation ever where SQL is going to force you to use the nolock hint. Using it is your choice, as with just about anything else.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 17, 2013 at 1:45 am
kapil_kk (7/17/2013)
GilaMonster (7/16/2013)
Or you could just remove the nolock hints entirely and remove any chance of their nasty side effects causing you problems.See - http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx
Gail,
Can you please tell me that when we have to use NOLOCK option as it gives us inappropriate data in result?
It doesn't necessarily give you inappropriate data each time. But there is a chance, which is worse enough.
You can use it when you don't want to have an impact on the source table, e.g. you don't want to have any locking. For example in a reporting scenario. But only if , and only if, your manager, the boss of your manager and everyone else looking at the report agrees that the data they are viewing could be wrong.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
July 17, 2013 at 9:16 am
kapil_kk (7/17/2013)
Voide (7/16/2013)
riya_dave (7/16/2013)
hiselect * from tableA with(nolock) a
join tableB with(nolock) b
on a.id = b.id
where a.date > getdate()
i am getting error incorrect syntax near a
As Gail said, why nolocks?
Also alias names for tables either follow the table name itself or the word 'as', nothing else.
Because, if you use NOLOCK then there is a chance of get inappropriate data...
Suppose you have opened a transaction and made some changes to the table and didn't Commit the transaction... After that you are using SELECT statement using NOLOCK option then you will get the modified data as the transaction was not committed... Then you ROLLBACK the transaction and again run the SELECT statement with NOLOCK then you will get your previous data...
We may have misunderstood each other 🙂 I wasn't advising him to use NOLOCK.
July 17, 2013 at 10:21 am
Voide (7/17/2013)
kapil_kk (7/17/2013)
Voide (7/16/2013)
riya_dave (7/16/2013)
hiselect * from tableA with(nolock) a
join tableB with(nolock) b
on a.id = b.id
where a.date > getdate()
i am getting error incorrect syntax near a
As Gail said, why nolocks?
Also alias names for tables either follow the table name itself or the word 'as', nothing else.
Because, if you use NOLOCK then there is a chance of get inappropriate data...
Suppose you have opened a transaction and made some changes to the table and didn't Commit the transaction... After that you are using SELECT statement using NOLOCK option then you will get the modified data as the transaction was not committed... Then you ROLLBACK the transaction and again run the SELECT statement with NOLOCK then you will get your previous data...
We may have misunderstood each other 🙂 I wasn't advising him to use NOLOCK.
:-P:-P
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply