Forum Moderators: open

Message Too Old, No Replies

MSSQL stored procedure vs view

         

stevelibby

11:59 am on Dec 14, 2007 (gmt 0)

10+ Year Member



hi
i have turned my attention to mssql database to speed things up. Now i have a table of 40000 thousand records, each row or group of rows have a priority listing between 1-9, so if i wanted to as invariably i do show the top 5 order by priority, from a static point of view it would scan the whole table.
Now if create a view with that query in and lets say where priority < 5 so that i would reduce to 3000 records
or
should create a storded procedure with that same query.

whats the difference between the ways?

syber

2:40 pm on Dec 14, 2007 (gmt 0)

10+ Year Member



Creating a View or Stored procedure will not in itself stop the scanning of the whole table. However, creating a Clustered Index on Priority will cause only the first 3000 records to be read in your example - no matter if it is accessed with a query, View or Stored Procedure.

The difference between a View and a Stored Procedure is that a View is a query that has been given a name and a Stored Procedure is a SQL script that has been given a name. Stored Procedures have an added advantage of being able to accept and return parameters.

stevelibby

12:22 pm on Dec 15, 2007 (gmt 0)

10+ Year Member



thank you for that, being relatively inexperienced with complicated db.
I have a table with 40000 records in it, how can i make things go quicker. If i created a new table with counties in it and then joined it, then when any searches where done would that make queries go quicker?

syber

12:54 pm on Dec 15, 2007 (gmt 0)

10+ Year Member



A table with 40000 records is relatively small for MSSQL Server. Good indexing will give you the most speed improvement.

Joining to another table will not speed things up in itself. However, if you replace columns such as county with a code the base table will process faster because the rows are smaller.