Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

collating records from different SQL Server tables


  • Please log in to reply
4 replies to this topic

#1 BobLewiston

BobLewiston

  • Members
  • 69 posts
  • OFFLINE
  •  
  • Local time:09:03 AM

Posted 16 March 2009 - 12:14 AM

I'm starting to learn SQL Server. As part of that effort, I'm experimenting with accessing AdventureWorks sample databases.

In database AdventureWorks, I've been accessing table Person.Contact. Although in that table there are columns for a phone number and an email address, there are no columns for a postal address. I see columns for a postal address in table Person.Address, but in that table there is no column for a numerical value ContactID, or for a string value for the contact's name, as there is in table Person.Contact.

It seems to me, especially because each of these two tables' names start with "Person.", that these tables are somehow linked. However, I don't see any columns in either table which seem to allude to any other tables. For what it's worth though, each of the two tables has a column called "rowguid", the purpose of which I don't understand.

I'd like my app to display in a WinForm all the information available for each contact, but I don't know how to locate the Person.Address record corresponding to a given Person.Contact record. Can anybody tell me how to do this?

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:07:03 AM

Posted 16 March 2009 - 08:08 AM

Selecting a record from a database is SQL 101. W3Schools has a decent generic set of lessons for working with SQL.

The records are likely linked by the user id, although without seeing the actual columns of the table, I can't say for sure. Since several people could have the exact same contact address, it makes no sense to have the same address repeated over and over. The addresses are there once, and the names are linked to them. You will need to combine this:
http://www.w3schools.com/sql/sql_syntax.asp
with this:
http://www.w3schools.com/sql/sql_where.asp

EDIT: I am a little confused. In one thread, you say that you an not access a database programatically. This post seems to indicate that you can.

#3 BobLewiston

BobLewiston
  • Topic Starter

  • Members
  • 69 posts
  • OFFLINE
  •  
  • Local time:09:03 AM

Posted 16 March 2009 - 09:39 AM

groovicus:

Thanks for the links; I'll check them out.

>I am a little confused. In one thread, you say that you an not access a database programatically. This post seems to indicate that you can.

I couldn't do it when I started that thread, now I can. It was partly a matter of finally getting the databases installed correctly, partly just learning how to access them correctly.

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:07:03 AM

Posted 16 March 2009 - 11:16 AM

So I can lock the other thread then?

#5 BobLewiston

BobLewiston
  • Topic Starter

  • Members
  • 69 posts
  • OFFLINE
  •  
  • Local time:09:03 AM

Posted 16 March 2009 - 11:57 AM

Yes. Sorry, I guess I should have mentioned the issue was resolved.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users