faqts : Computers : Databases : Microsoft SQL Server

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 3 people (67%) answered Yes
Recently 2 of 3 people (67%) answered Yes

Entry

Database: Microsoft SQLserver: SQL: Key: View: How select tables via primary+foreign key, using SQL?

Dec 22nd, 2003 13:29
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 22 December 2003 - 10:25 pm -------------------

Database: Microsoft SQLserver: SQL: Key: View: How select tables via 
primary+foreign key, using SQL?

---

Steps: Overview:

 1. -Create a table with a primary key

 2. -Create a table with a foreign key

 3. -Open the database with this tables

 4. -Type the following SQL query:

      SELECT * from Person, Email WHERE Person.Personkey = 
Email.Personkey;

      ---

      In general:

      SELECT * from <Tablename1>, <Tablename2> where 
<Tablename1>.<Primary key> = <Tablename2>.<Foreign key>;

 5. -You will see something similar to the following:

+-------------------------------------------------------------------+
|      NAME          PERSONKEY   EMAILADDRESS              PERSONKEY|
|-------------------------------------------------------------------|
|      John Doe	     1	         john.doe@test.com	   1        |
|      John Doe	     1	         j.d@aol.com	           1        |
|      John Doe	     1	         johnny6@yahoo.com	   1        |
|      Vanessa Beau  2	         vanessa@vendor.com	   2        |
|      Vanessa Beau  2 	         vanessa.beau@yahoo.com	   2        |
|      Vanessa Beau  2	         v.b.@aol.com	           2        |
+-------------------------------------------------------------------+

---
---

Internet: see also:

---

Database: Microsoft SQL server: SQL: Operation: Overview:Can you give 
an overview of SQL operations?
http://www.faqts.com/knowledge_base/view.phtml/aid/27560/fid/147

----------------------------------------------------------------------