Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 250 Time: 01:22 - Apr 11, 2008  

sukeshjph

I want to know about derived tables in sql server 2005

Derived tables in sql server 2005 can be used for joins which treats a subquery as a tabke..can i know some more about this and its drawbacks ...where to use it and where not to.

Categories

Answer Discussion
Tutorials

 

Suleman

Date:: Jul 16, 2010

Time:: 10:19

Hi Sukeshiph,

A derived table is a virtual table that's created and populated on the fly from a select statement.

In concept this is similar to creating a temporary table and then using the temporary table in your query, but the approach is much simpler, coz it can be done in one step. This can be tremendously useful in certain situations.

Some times derived tables can be most useful, for instance you need to create a view for a single query and then you want to use it within another query and after that the view should be dropped because nothing else uses this view, in this context derived tables suit you best and benefits you by saving to create you a catalog entry in the form of view in the server.

For repeated queries, a SQL derived table used multiple times performs well with cached definition. It will not degrade your performance. A SQL derived table differs from a temporary table in that a SQL derived table exists only for the duration of the query, while a temporary table exists until the SQL Server are recycled or the temporary table is dropped manually and also it uses lots of disk space than a derived table in the temdb database.

So it's better to make use of Derived tables wherever possible by eliminating the rearely used or one time only views and by eliminating the temporary tables.

You would gain a lot of performance gain using a derived table when compared to using a temparory table as illustrated below:

Steps needed to read from a temporary table:

1. Lock tempdb database
2. CREATE the temporary table (write activity)
3. SELECT data & INSERT data (read & write activity)
4. SELECT data from temporary table and permanent table(s) (read activity)
5. DROP TABLE (write activity)
6. Release the locks

Compare this with the number of steps required for a derived table:

1. CREATE locks, unless "read uncommitted" isolation level is specified.
2. SELECT data (read activity)
3. Release the locks


Thus derived tables require less I/O and less disk space.

Hope this was helpful.

admin

Date:: Mar 31, 2012

Time:: 13:57

The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points.

The Quomon Team

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10354

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es