Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query to Indexed View

Author  Topic 

sanj
Starting Member

22 Posts

Posted - 2009-01-04 : 08:40:25
Hi,

I have a query that is used on several pages on a site (same query), would it be more effecient to create a Indexed view of this rather than query the database on each page?

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-04 : 12:43:09
why not make it a procedure/function and call it everywhere you need.
Go to Top of Page

sanj
Starting Member

22 Posts

Posted - 2009-01-04 : 17:20:12
Thanks for the suggestion I will try this.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-04 : 17:29:50
I don't understand how an indexed view makes it so that you don't have to query the database. Indexed views are used for performance reasons and does not eliminate the need to query it. You can typically get away with just indexing the underlying tables rather than using indexed views though. Indexed views are a major pain.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sanj
Starting Member

22 Posts

Posted - 2009-01-04 : 17:40:41
Thanks ref indexed views - what sort of performance over a query would I get from stored proc ?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-04 : 18:16:51
We can't calculate what kind of boost you'd get by using a stored procedure. Prepared statements from an application can be just as fast as a stored procedure.

You'll need to do some load testing to determine what works for you.

If I have a say about the data access, I demand that stored procedures be used. However I don't always have a say, so I've got several applications in production that do not use stored procedures but luckily most of those use prepared statements.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sanj
Starting Member

22 Posts

Posted - 2009-01-04 : 19:08:44
Thanks Tara,

I'm not too sure the difference between a Prepared statement, stored procedure are there any advantages/dis-advantages?

to be more specific most of the queries on my app return the same information, with some pages that filter this information on the ID (primary key)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-04 : 23:45:14
Please google and search this site about the advantages and disadvantages. It has been discussed at length numerous times. It is a very heated debate. I'm on the side of the fence that is very pro stored procedures. A lot of developers are very against stored procedures. I'm a DBA.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -