Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 21st, 2008, 06:59 AM
Zuhaib.bukhari Zuhaib.bukhari is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Location: Karachi, Pakistan
Posts: 1 Zuhaib.bukhari User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 51 sec
Reputation Power: 0
Send a message via Yahoo to Zuhaib.bukhari
Facebook Orkut
Any body help me out.

[SIZE=4]Just tell me How I create relations in Tables in Sql Server 2000. pls I need ur Help.

Reply With Quote
  #2  
Old June 23rd, 2008, 09:42 AM
dragonbite dragonbite is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Connecticut, USA
Posts: 34 dragonbite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 37 m 44 sec
Reputation Power: 1
Quote:
Originally Posted by Zuhaib.bukhari
[SIZE=4]Just tell me How I create relations in Tables in Sql Server 2000. pls I need ur Help.

Code:
SELECT field1, field2, fieldN

FROM table1 INNER JOIN table2 ON table1.field1=table2.field1

INNER JOIN => the relationship (INNER JOIN means "give me all of the records where these two fields match in these two tables)
ON => what field do you want to match between tables. They do not need the same name but the same type.
Code:
The tables...

Table1
UserId       FName
-------------------
1             John
2             Dave
3             Bob
5             Drew

Table2
UserId       LName
-------------------
1             Smith
2             Jones
4             Gates


The Code ...

SELECT Table1.FName, Table2.LName
FROM Table1 INNER JOIN Table2 ON Table1.UserId=Table2.UserId

The Results ...

FName       LName
-------------------
John          Smith
Dave         Jones

NOTE: 

Since Table1 does not have a UserId of "4" and Table2 does the record in Table2 is not grabbed. Only where the record exists in BOTH tables will it show up.

Likewise, Table1 does has a UserId value of "5" and Table2 does not so that record is not grabbed.


If you are going to do much with SQL then I highly recommend getting a book that goes over it in detail.

For example, there are different types of JOIN between tables; INNER, OUTER and each has their own benefits and purposes.

I started with a Wrox book that has helped me. If you are going to be doing a lot of writing queries and such, perhaps http://www.wrox.com/WileyCDA/WroxTitle/productCd-076457955X.html would help.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Any body help me out.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT