Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Linking Database Tables

Posted on 2008-10-09
4
Medium Priority
?
175 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

773 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