Solved

view vs table in sql server

Posted on 2011-03-08
4
602 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
4 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanx
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now