Tutorials
Resources
Forum
Reviews
Communities
Interview
Jobs
Projects
Training
Your
Ad
Here
Silverlight Games
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Polls
|
Revenue Sharing
|
Lobby
|
Gift Shop
|
Prizes & Awards
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
krishnavenikal...
(2)
Shafi Imran
(1)
Last 7 Days
Anil Kumar ...
(582)
Nikhil Gaur
(551)
Abhisek Panda
(445)
more...
Resources
»
Articles
»
Databases
»
List tables that doesn't participate in any relationships ...
Posted Date: 03 Jan 2007
Resource Type:
Articles
Category:
Databases
Author:
Vadivel Mohanakrishnan
Member Level:
Diamond
Rating:
Points
: 7
Introduction
This article helps in listing those tables which aren't participating in any relationships between other tables.
This query returns those tables which satisfy the below two conditions:
1. Tables that do not contain any Foreign Key referencing other tables.
2. Tables that are not referenced by other tables using foreign key constraints.
Solution:
Till SQL Server 2000 days we used to write the below scripts [This still works with SQL Server 2005 also].
Select [name] as "Orphan Tables" from SysObjects where xtype='U' and id not in
(
Select fkeyID from SysForeignKeys
union
Select rkeyID from SysForeignKeys
)
Solution which works only with SQL Server 2005:
Method 1:
Select [name] as "Orphan Tables" from Sys.Tables where object_id not in
(
Select parent_object_id from Sys.Foreign_Keys
union
Select referenced_object_id from Sys.Foreign_Keys
)
Method 2:
Select ST.[Name] as "Orphan Tables"
from Sys.Foreign_Keys as SFK Right Join Sys.Tables as ST
On ST.object_id = SFK.parent_object_id Or
ST.object_id = SFK.referenced_object_id
Where SFK.type is null
Responses
No responses found. Be the first to respond and make money from
revenue sharing program
.
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
to add tags.
(No tags found.)
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
How to find the number of days in a month
Previous Resource:
provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
Return to Discussion Resource Index
Post New Resource
Category:
Databases
Post resources and
earn money
!
Related Resources
Find tables which doesn't have Primary Key ...
Don't prefix user defined stored procedure with "SP_" ...
sp_executesql( ) vs Execute() -- Dynamic Queries
Fun with SQL Server ...
Rolling back a truncate operation!
Delete VS Truncate ...
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use