473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Tables in Parent-Child order

Greetings,
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.

TIA

Nov 8 '05 #1
7 2410
(pa***************@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, es****@sommarskog.se

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

Nov 8 '05 #2
thanks for the help. i got what i want. thnnx again

Nov 9 '05 #3
Get a copy of TREES & HIERARCHIES IN SQL and learn how to do it one
simple query.

Nov 9 '05 #4
thanx for the reply. i'll see to it.

Nov 9 '05 #5
The nested set method you will see is:-

1) Difficult to maintain
2) Does not scale nor perform well out of the lab and in the real
world.

A better method is that developed by Itzik Ben Gan, information here:
http://www.windowsitpro.com/Articles...layTab=Article

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"--CELKO--" <jc*******@earthlink.net> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Get a copy of TREES & HIERARCHIES IN SQL and learn how to do it one
simple query.

Nov 9 '05 #6
The nested set method you will see is:-

1) Difficult to maintain
2) Does not scale nor perform well out of the lab and in the real
world.

A better method is that developed by Itzik Ben Gan, information here:
http://www.windowsitpro.com/Articles...layTab=Article

The challenge is still there, you code up using the nested set model and
i'll using Itzik's method; i have a data set of over 700,000 rows which is a
message board so will be a good test.

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"--CELKO--" <jc*******@earthlink.net> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Get a copy of TREES & HIERARCHIES IN SQL and learn how to do it one
simple query.

Nov 9 '05 #7
I have used the solution mentioned by Tony for a folder/subfolder
document management solution and it works quite well.

Nov 11 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: thatseattleguy | last post by:
I'm stumped. Visit: http://positivesweat.com/class.html ....and look at the tables in the middle labeled "morning" and "evening". Do this in both IE and Firefox. The tables appear to me to...
2
by: Felix Finch | last post by:
I am a self taught SQL novice, possibly beneath contempt :-) Two questions here. One is how to define two tables whose columns reference each other, the other is whether trying to do this means...
2
by: Patrick Finnegan | last post by:
DB2DART detects problems with SYSIBM.SYSSECTION and SYSIBM.SYSSTMT .. I cannot connect to or drop these tables(system objects). What are my options besides a db restore? Thanks in advance. ...
3
by: Seba | last post by:
For db2 UDB I need to get dependency information for views. What I'm looking for is the tables that have the source information for the view. i.e. : if the following view was defined in my...
2
by: Marco Simone | last post by:
Hi, I have 4 tables, tblCompany, tblA, tblB and tblC. tblA, tblB and tblC contain same type of data, they should be in one table, but since there are many fields, I split it into 3 tables. Each...
4
by: Blue Apricot | last post by:
How can I prevent certain Class properties from cascading from a parent table to its children? Specifically, I have a table that acts as a container (I call it class="page"), with a certain...
17
by: Frank Swarbrick | last post by:
Consider the following... - A customer table with a customer number column as the primary key, and also a column called SHORTNAME. - An account table with an account number column as the primary...
1
by: Landon | last post by:
Ver: Access 2003 Hi everyone and thanks in advance, General Issue: I want to make a table whose data polls from two other tables and will update (add new records) if additions are made to...
2
by: murderof1 | last post by:
Hello, I'm new to Javascript, but I'm trying to create html tables based off a checkbox action. Is it possible to do this on the same page? I've noticed that document.write() will create the...
1
by: DMAGIC448 | last post by:
I am trying to figure out how to add records to multiple tables w/ one form. I am making a database for a Home DayCare and I want to add/update records for 5 tables (Student info, Parent 1 Info,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.