Join two tables in sql server 2008

I just created a new table and I want to join it to an existing table using the Primary key in the original table as a foreign key in the new table.  In sql server 2000I did this via a diagram.  I don't have diagrams here.  How can I complete this task otherwise?

Thanks!
Bob SchneiderCo-OwnerAsked:
Who is Participating?
 
lucky20Connect With a Mentor Commented:
There are various types of joins.. you can find here ..
SQL Joins

sql table1:
empid(pk)
empname



sql table2:
eid(fk) from <sqltable1>
deptid(pk)
dept_name


sql st:
select t1.empid, t1.empname, t2.dept_name from sqltable1 t1,sqltable2 t2 where t1.empid=t2.empid
0
 
derekkrommConnect With a Mentor Commented:
Right click the table with the PK, click design
From the top menu, Table Designer, Relationships

Add a relationship, on the "Tables and Columns Specification", click the "..." button to select the table/columns
0
 
Bob SchneiderCo-OwnerAuthor Commented:
On the solutioin by derekkrom, when I try to create a relationship it joins the PK table to itself?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
OP_ZaharinConnect With a Mentor Commented:
Sample:

TableA
   - Id (Primary Key)
   - Description

TableB
   - Id (Primary Key)
   - TableAId (FK to TableA)

select *
from
    TableA a
        left join
    TableB b
        on
            a.Id = b.Id
0
 
derekkrommConnect With a Mentor Commented:
Sorry, you want to do that on the table that contains the FK, not the PK. Apologies.
0
 
OP_ZaharinCommented:
this is a sql statement to do the foreign key:

CREATE TABLE STOCK
(Stock_ID integer primary key,
StockIn_Date datetime,
Description char(100),
Supplier_SID integer references SUPPLIER(SID),
Amount double);
0
 
OP_ZaharinConnect With a Mentor Commented:
Further explanation - SUPPLIER is the foreign table name and SID is the primary key in SUPPLIER table
0
 
Bob SchneiderCo-OwnerAuthor Commented:
Awesome.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.