Solved

Linking Database Tables

Posted on 2008-10-09
4
170 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
[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
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

622 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