Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 usage of foreign key

Author  Topic 

salmonraju
Yak Posting Veteran

54 Posts

Posted - 2006-10-21 : 05:04:07
hello,
I have two tables say tab1,tab2 .
tab2 contains a foreign key relationship with tab1 (tab1 contains primary key)

will it possible to write a command like this
select * from tab2 where tab1.id=5
i.e, can i check a feild in parent table (tab1.id) in child table
before retrival. please suggest me if u can

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-21 : 06:24:08
It seems you need to use Joins

Select C.columns from Child C inner join Parent P
on C.id=P.id

or post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-10-21 : 07:26:35
What is the linking field between both the tables?


select * from tab2 where tab1.id=5
You can not do like this.. first you require to join the tables using the join. and then in the where clause you can specify the conditions.


You require to Learn SQL,Do refer to the following links.

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page
   

- Advertisement -