Solved

view vs table in sql server

Posted on 2011-03-08
4
612 Views
Last Modified: 2012-05-11
i am using query from C# to sql server. my question is, i can get data from the views as well as tables. which one is better for performence for query? which one is better to use for select query?
please help
0
Comment
Question by:Amitava_Mukherjee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 125 total points
ID: 35068390
It depends what it is a View of. If it is just a subset of a single table then the View will be as quick as the table. Views can be indexed so Views that draw data from multiple tables can be quicker than the same query run inline because the view can be indexed independently of the underlying tables.
0
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 250 total points
ID: 35068427
A view by general definition is a virtual table as it selects with more or less complex SQL from one or more real tables. From that perspective you can do both.

A view has the advantage to keep the knowledge about the queries at the database level. You can argue, that the business logic level of the c# application is also a good place for that, but the view can of course be used by many applications connecting to the same database.

Doing stored procedures instead of views could even be a better choice for keeping cahed meta data like the execution plan.

What you can't do is update a view, so you'd need to write changes to the underlying tables.

Pros and cons mainly are about abstraction layers of the application business logic and database/persitence layer. See here for further discussion: http://stackoverflow.com/questions/1004974/use-sql-view-or-sql-query

Bye, Olaf.
0
 
LVL 5

Assisted Solution

by:mayankagarwal
mayankagarwal earned 125 total points
ID: 35068461
if your view is based on multiple tables, and if you have to put loops in your code to access the data from the multiple tables and for sure view will give you the better performance, becuse the number of hits to the database will be descreased.

0
 

Author Closing Comment

by:Amitava_Mukherjee
ID: 35068565
thanx
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question