Link to home
Start Free TrialLog in
Avatar of sdc248
sdc248Flag for United States of America

asked on

view or stored procedure

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.
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Explicitly naming the columns should perform better.
SOLUTION
Avatar of alpmoon
alpmoon
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sdc248

ASKER

Got it. Thanks guys.