Solved

Linking Database Tables

Posted on 2008-10-09
4
156 Views
Last Modified: 2013-11-07
Hi Experts,

Is there a way of being able to create a table in a database that is linked to data in other tables? By this I mean rows/columns (and the data) are pulled in from other tables and are dynamically refreshed/updated.

I am using this within an application so OLEDB commands on how to achieve this would be the most useful.

Thanks in advance

Tom
0
Comment
Question by:TommyTwoPints
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22684588
Not a table, but a view yes.


create view vw_MyView
as
select a.column1, b.column2
from yourtable1 a
join yourtable2 b
on a.id=b.id


then just select from the view instead of the table.
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 22684609
Hi Brandon,
Thankyou for your quick response. Can we store these views? Will they be dynamically updated if the table they are linked to is changed.
Also; If Column1 doesnt exist anymore; what would happen to the view? Would there be some sort of notification/error?
Thanks
Tom
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22684629
When you create the view it is saved in SQL server.  There is no "dynamic update" as the data is not actually stored in the view.  Think of it as a saved select statement.

If column 1 doesn't exist, then you will need to remove it from the view.  If you use the select * from tablea join table...... syntax, then you can issue the sp_refreshview command to refresh it's column after you remove the column.

And yes, there would be an error if you attempt to select from it and the column no longer exists if you do it how I have it above.  I know in SQL 2k, not refreshing the view would cause problems where data would appear under the wrong heading but i think it would still work.  But if you always issue the sp_refreshview command, it will be fine.
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 22684677
Thanks alot Brandon, you've been a great help!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

20 Experts available now in Live!

Get 1:1 Help Now