troubleshooting Question

view or stored procedure

Avatar of sdc248
sdc248Flag for United States of America asked on
Microsoft SQL Server
4 Comments2 Solutions337 ViewsLast Modified:
Hi:

I need to make sure the data rows selected in a query are unique. The database table is huge. I did a test by running the following query and it takes 10-20 seconds to complete.

SELECT COUNT(*) FROM (SELECT DISTINCT * FROM dbo.MyTable ) AS a

I wonder which appraoch would have better performance:
1. simply put the above statement in my stored procedure.
2. create a view that does SELECT DISTINCT * FROM dbo.MyTable, and then select data rows from the created view from my stored procedure.

Please comment. Thanks.
ASKER CERTIFIED SOLUTION
TheGiops

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros