Solved

Linking Database Tables

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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