Solved

Linking Database Tables

Posted on 2008-10-09
4
159 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

13 Experts available now in Live!

Get 1:1 Help Now