To find foreign keys which hase "enforce relationship for replication" is ticked.

Sql Server 2000

I want to know all foreign key names in one of database where this option is checked.
Enforce relationship for REPLICATION

Result format

Relationship_name    PrimaryKeyTable   ForeignKeyTable
---------------------    -------------------    -------------------

MateenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HuyBDCommented:
Try this!

select sysobjects.name as Relationship_name ,t1.name as PrimaryKey,
syscolumns.name as ForeignKeyTable,T3.name as PrimaryKeyTable,t2.name as ForeignKeyTable from sysobjects
inner join sysforeignkeys as b on  sysobjects.id=b.constid
inner join syscolumns on syscolumns.id=b.fkeyID and syscolumns.colid=b.fkey
inner join syscolumns as T1 on t1.id=b.rkeyID and t1.colid=b.rkey
inner join sysobjects as T2 on t2.id=syscolumns.id
inner join sysobjects as T3 on t3.id=T1.id
where sysobjects.xtype='F'
0
MateenAuthor Commented:
Hi HuyBd

The format and columns are exactly what I want.

It is also showing those foreign keys where the option "enforce relationship for replication" has been not ticked.

I want to show only all those foreign keys where the option "enforce relationship for replication"  has been ticked/set.

After seeing the result, I would remove all those replication relationship.
0
imran_fastCommented:
Hi Mateen!

use this
select sysobjects.name as Relationship_name ,t1.name as PrimaryKey,
syscolumns.name as ForeignKeyTable,T3.name as PrimaryKeyTable,t2.name as ForeignKeyTable from sysobjects
inner join sysforeignkeys as b on  sysobjects.id=b.constid
inner join syscolumns on syscolumns.id=b.fkeyID and syscolumns.colid=b.fkey
inner join syscolumns as T1 on t1.id=b.rkeyID and t1.colid=b.rkey
inner join sysobjects as T2 on t2.id=syscolumns.id
inner join sysobjects as T3 on t3.id=T1.id
where sysobjects.xtype='F'
AND sysobjects.STATUS < 3000                              <==== change
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

imran_fastCommented:
The above Query is applicable for sql server 2000 only.
0
Scott PletcherSenior DBACommented:
SELECT OBJECT_NAME(constid) AS [Relationship Name],
    OBJECT_NAME(rkeyid) AS [Primary Key Table],
    OBJECT_NAME(fkeyid) AS [Foreign Key Table]
FROM sysreferences WITH (NOLOCK)
WHERE OBJECTPROPERTY(constid, 'CnstIsNotRepl') = 0
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MateenAuthor Commented:
1) HuyBD : Complete work done except the line
         << AND sysobjects.STATUS < 3000   >>
        added by imran_fast.

2) ScottPletcher:
    Completely different technique.
    Usage of only one table.
   
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

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.