?
Solved

view vs table in sql server

Posted on 2011-03-08
4
Medium Priority
?
614 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 500 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 1000 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

752 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