January 22, 2011 at 8:27 am
I have few basic questions (Consider TableA as a very big table with over 3000000 rows):
1. Is this the right way to check some condition:
IF EXISTS(SELECT * FROM TableA WHERE ColA = 'blahblahblah')
BEGIN
--------------
--------------
END
2. Is this correct:
SELECT * FROM TableA
WHERE ColA <> 64
3. Is this corect:
SELECT * FROM TableA
WHERE ((ColA = 5) or (ColA = 8))
4. Is this correct:
SELECT 'ColB' = CASE WHEN (A.ColA IN(select * from TableB) and A.Colc = '') then 'BlahBlahBlah'
ELSE 'Lolz' END
FROM TableA A
January 22, 2011 at 8:04 pm
sql_butterfly (1/22/2011)
I have few basic questions (Consider TableA as a very big table with over 3000000 rows):1. Is this the right way to check some condition:
IF EXISTS(SELECT * FROM TableA WHERE ColA = 'blahblahblah')
BEGIN
--------------
--------------
END
2. Is this correct:
SELECT * FROM TableA
WHERE ColA <> 64
3. Is this corect:
SELECT * FROM TableA
WHERE ((ColA = 5) or (ColA = 8))
4. Is this correct:
SELECT 'ColB' = CASE WHEN (A.ColA IN(select * from TableB) and A.Colc = '') then 'BlahBlahBlah'
ELSE 'Lolz' END
FROM TableA A
Gosh... do what's right and setup some tests and run them on your own. How are you expecting to really learn anything if you don't do your own homework or interview questions?
--Jeff Moden
Change is inevitable... Change for the better is not.
January 23, 2011 at 12:29 am
Hello Sir, its not like I didn't give it a try. I read a lot and tried lotz of options and tested them as well. However whatever I have tested not giving me satisfying results. Suppose if a query is taking say 10 seconds originally, after lots of trials and testings based on knowledge gathering its taking same time. I have also checked with different combinations of indexes on tables as well with the help of DTA as well as certain DMVs like sys.dm_db_missing_index_details, sys.dm_db_missing_index_columns, sys.dm_db_missing_index_groups etc. Also kept in mind the index health in terms of defragmentation. Once I was done and not yet satisfied, then only I came here.
January 23, 2011 at 2:01 am
sql_butterfly (1/22/2011)
2. Is this correct:SELECT * FROM TableA
WHERE ColA <> 64
Think about it, if you want all rows except where ColA = 64, how else would you do it?
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
January 23, 2011 at 1:08 pm
The answer is simple, it depends. Each query is an answer to a different question. Without knowing the question, we can't tell you if the query is correct or not.
January 23, 2011 at 10:40 pm
sql_butterfly (1/23/2011)
Hello Sir, its not like I didn't give it a try. I read a lot and tried lotz of options and tested them as well. However whatever I have tested not giving me satisfying results. Suppose if a query is taking say 10 seconds originally, after lots of trials and testings based on knowledge gathering its taking same time. I have also checked with different combinations of indexes on tables as well with the help of DTA as well as certain DMVs like sys.dm_db_missing_index_details, sys.dm_db_missing_index_columns, sys.dm_db_missing_index_groups etc. Also kept in mind the index health in terms of defragmentation. Once I was done and not yet satisfied, then only I came here.
I'm a little skeptical of your answer because the code from one of the questions won't even pass a simple syntax check. :Whistling:
So how did you answer on the 4 questions and why?
--Jeff Moden
Change is inevitable... Change for the better is not.
January 24, 2011 at 7:16 am
sql_butterfly (1/23/2011)
Hello Sir, its not like I didn't give it a try. I read a lot and tried lotz of options and tested them as well. However whatever I have tested not giving me satisfying results. Suppose if a query is taking say 10 seconds originally, after lots of trials and testings based on knowledge gathering its taking same time. I have also checked with different combinations of indexes on tables as well with the help of DTA as well as certain DMVs like sys.dm_db_missing_index_details, sys.dm_db_missing_index_columns, sys.dm_db_missing_index_groups etc. Also kept in mind the index health in terms of defragmentation. Once I was done and not yet satisfied, then only I came here.
Seems that what you really want is performance tuning. This is a HUGE topic, and definitely not something you can learn from a few forum threads. Most importantly is that you could tune each of those queries to be blazing fast but totally hose other queries. There is no simple answer.
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply