You are here: Re: Tables in Parent-Child order « MsSQL Server « IT news, forums, messages
Re: Tables in Parent-Child order

Posted by Erland Sommarskog on 11/08/45 11:31

(pankaj_wolfhunter@yahoo.co.in) writes:
> I just wanna know if anyone can tell me how to get all user defined
> tables in parent-then-child manner. I mean all the parents should be
> listed first and then childs.
> I dont think there is any direct way to do this, but i am not able to
> form any sort of query to achieve this.
> Any help will be greatly appreciated.

I don't think I really understand what you want. In the general case
tables may have many parents, and it all can get quite messy.

This query first lists all tables that does not have a foreign key,
and then those that have.

select o.name
from sysobjects o
where o.xtype = 'U'
order by case when exists (Select *
from sysforeignkeys f
where o.id = f.fkeyid)
then 1
else 0
end, o.name

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация