Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Sql Server Programming

How do I check for a Foreign Key Relation???


hey, I have a table of users, each with a User ID.  my boss wants me to
figure out how to tell if a user's ID is used as a foreign key relation
anywhere. how do I do that?

I'm pretty sure it just involves a select statement, and count the rows. if
the rows is greater than zero than yes, there is an FK relation. but what do
I look for? I cant just look for the user ID 1. because other things have
ID's of 1 (like JobID and stuff)

any help is appreciated

check http://www.quicksqlserver.com/code/index.html  , this will allow for a
give database

--

Jack Vamvas
___________________________________
The latest IT jobs   - www.ITjobfeed.com
<a href="http://www.itjobfeed.com">UK IT Jobs</a>

"roger_27" <roge@discussions.microsoft.com> wrote in message

news:BD45E97D-BB83-4368-A390-B560B07B3A1D@microsoft.com...

On Mar 12, 4:48 pm, roger_27 <roge@discussions.microsoft.com>
wrote:

> hey, I have a table of users, each with a User ID.  my boss wants me to
> figure out how to tell if a user's ID is used as a foreign key relation
> anywhere. how do I do that?

> I'm pretty sure it just involves a select statement, and count the rows. if
> the rows is greater than zero than yes, there is an FK relation. but what do
> I look for? I cant just look for the user ID 1. because other things have
> ID's of 1 (like JobID and stuff)

> any help is appreciated

sp_help <tablename> If there are any foreign keys referencing the
table then that will appear down the bottom.

If you want to do it manually (i.e. noone has defined the
relationships but they still exists - bad db design) then look for the
same column name in other tables something like
select so.name, sc.name from sysobjects so inner join syscolumns sc on
so.id = sc.id where sc.name = 'user id'

-----------------------------------------------Reply-----------------------------------------------

I'm actually a .NET developer, not a DBA. these URLS are great. and they kind
of make sense. but I am not learned in the ways of SQL well enough to
decipher them.

can someone help me make it into a SQL statement I can put in my code?

the table is
[User]
the field I'm checking for as a foreign key is
UserID

my Database name is
MainDB

again thanks for the advice, but can someone give me a little more
direction? tanks.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc