Sql Server 2005 And Tree Structures

Mar 9, 2007

I am trying to traverse a tree structure like below,

1 Pets
--1.1 Cat
----1.1.1 Persian
----1.1.2 Bengal
--1.2 Dog
----1.2.1 Poodle
2 etc

I would like to be able to search by a keyword, i.e. Poodle, or the reference number, i.e. 1.2.1. I would prefer to do this all through a stored procedure if possible, it seems recursion is the way to go as the number of levels may increase in the future but i'm completely new to this. From what i've seen so far I would need a table structure with a parentID,NodeID,Name field and Primary key.

i.e,

ID...Name......Parent.....NodeID
1....Pets.........0............1
2....Cat..........1............1
3....Dog..........1............1
4....Persian.....2............1
5....Bengal......2............2
6....Poodle......3............1
etc

i've heard that SQL SERVER 2005 provides recursion through CTE, is this the recommended way/only way to achieve this?

Any tips on where to start would be really appreciated.

View 3 Replies


ADVERTISEMENT

Tree Structures In SQL

Jun 11, 2006

Hi,

i'm writing a app in c# and have to store Trees in a Database.

I'm working with Datasets for the exchange between the DB and the App.

The trees have the same options like the windows folders. If u delete a node, all subnodes should be deleted too.

But something a Foreign Key from ParentID references (Id) with the delete-Rule on cascade seems not to be possible, because of multiple cascade Paths or cycles. Do i have to add some xtra constarins:

Not Possible:

create Table tree (
Id varchar Not null,
ParentId varchar Not null,
Constraint pk1 Primary Key (Id),
Constraint fk1 Foreign Key (ParentId) references tree(Id)
On Update Cascade
On delete CAscade
)


Do i have to write triggers, which delete The subnodes too and set the Update-/deleterulr on NO Action

Greetz

View 1 Replies View Related

Tree Structures...

Oct 24, 2006

Does anyone know any good links for SQL tree structures and example queries and stuff... I cant really find anything part from the standard example of emplyee, boss, salary which explains how to create the tree table...(dun dis bit) I did notice a book but I live in a little village so cant go get it till wekend?

I'm desperate, reli need to work out how too do this.....

View 14 Replies View Related

Concurrency Issues With Tree Structures.

Jul 23, 2005

Hi,I'm currently implementing a database with a tree structure in a table. Thenodes in the tree are stored as records with a column called "Parent". Theroot of the tree has a "NULL" parent. The path to each node is stored inthe column "Path" and is of the form "000010000200003" etc. Thelatter enabling me to fetch subtrees using the "LIKE" predicate. I alsohave created the relation "ID" <-> "ID_Parent, effectively the table isrelated to itself. I did this so that an attempt to remove a parent whenthat parent still has children will fail due to referential integrity.Unfortunately, in order to delete subtrees, I have to first set all of thenodes in the subtree to point to the "NULL" parent so that I don't getcaught with integrity errors during deletes.Unlike a typical linear system, any given node record is related to morethan one of the other records. What I mean is it is possible to follow achain from any given node back to the root (ancestors) or collect a seriesof branches and leaves (descendants) and so it is not reasonable to considerany given node in isolation. Changes to any given descendant can triggerchanges which are propagated to it's ancestors. I am not using recursion todo this, rather, I am using an iterative approach to select and update theparent, then the parents parent, etc. according to it's new state (given bythe state of it's immediate descendants), right back up to the root.Now, the problem comes when I consider concurrency with respect to thisscheme. It seems to me, that locking the record I am updating is notsufficient to ensure clients are kept synchronised or the integrity of thetree structure is correct. I think I need to lock all ancestors of the tree(HOLDLOCK) before performing any operation on a given node. Is thisreasonable? Also, consider the "delete" problem given above. I reallyshould HOLDLOCK on the entire subtree of any node I wish to delete as I amgoing to set the entire subtrees parent values to NULL. I don't wantanother client to perform a read on part of the subtree while the nodes are"parentless" pending deletion.Secondly, I am not sure how to handle synchronization of the tree for eachclient. How does each client know when a change has been made to the tree?Consider a client holding a copy of the tree in memory. Another clientdeletes a subtree. The first client attempts to update one of the deletedsubtree nodes and fails because the node no longer exists. At this point,in the eyes of the first client, all of the ancestors and all of thedescendants of the node in question must become suspect. Should thesoftware now attempt to re-build this part of the tree? It seems that anyoperation on any of the nodes in the tree will potentially make a lot ofother nodes suspect and so my application will be doing a lot of updating.I would be interested to hear any insights people have on these issues,particularly those implementing a "file system" structure in their databaseor similar. How do you deal with these concurrency issues when manipulatingtrees?ThanksRobin

View 4 Replies View Related

How To Get 2 Level Tree Node In The Sql Server 2005

May 30, 2008

hi,

How to get 2 level tree node in the sql server 2005. We have table with data.On load we populate the tree in Asp.net.

Regards,
Vinayak Panchal

View 2 Replies View Related

Time Series In SQL Server 2005 Desicion Tree Interpretation

Aug 12, 2007



Dear All
The problem is I am going to predict the production for different category of product.
attributes are
year - key
A production - predict only
B production -predict only
C production -predict only

And in the SQL it is impossible to to give input and predict (I am not sure whether that is a error or not).

And in the decision tree
for the
Product A - get as product A >=12324
Product B year > 2000
Product C product C >=35454


I want to know why the label is changing time to time.
Please help me on this. Thank you
Menik



View 3 Replies View Related

SQL 2012 :: Sort Tree Members In Right (tree) Structure?

Apr 6, 2015

I got assignment, how to make it appear in the right order .

/* DROP TABLE EMP
SELECT * INTO Emp FROM (
SELECT 'A' EmpID, NULL ManID, 'Name' EmpName UNION ALL
SELECT 'MAC' EmpID, 'A' ManID, 'Name__' EmpName UNION ALL
SELECT '1ABA' EmpID, 'MAC' ManID, 'Name____' EmpName UNION ALL
SELECT 'ABB' EmpID, '1ABA' ManID, 'Name______' EmpName UNION ALL
SELECT 'XB' EmpID, 'A' ManID, 'Name__' EmpName UNION ALL
SELECT 'BAC' EmpID, 'XB' ManID, 'Name____' EmpName ) b
*/

[code]....

View 2 Replies View Related

Copy SQL Data Structures From One Server To Another

Oct 17, 2007

Hello,
I have a sql database server (let call it server A) which has SQL program files installed on C:, and SQL data structures MSSQL (include subdirectories BAckup, DATA, FTDAT, JOBS, LOG, REPLDATA) on F:. A new server (call it server B) was cloned of server A but only at the C: partition. I still need to manually copy the SQL data structure on F: drive from A to B. The purpose of setting up server B is to test the restore of backup of server A and eventually want it to serve as the standby server should server A crashes. My questions are
1. Can MSSQL directory be copied from A to B without stopping the SQL server service on A first?
2. I will use robocopy for copying data over, what switches should I use to retain all database file security, permission, etc..
3. Currently I can not start the SQL service on server B because part of MSSQL directory is missing from the F: drive. so theorically, after I manually copy that folder over, I should be able to start the sql service. Am I right? Is there any steps that I might have overlook here. Any errors I might encounter doing it this way

Once I can get the sql started, I can take care of the restore part.
Thanks for any insights or suggestions you can provide on this.


View 7 Replies View Related

Is There A Way To Open SSRS 2005 Tree View In A Table In A Details Row Upward?

Apr 4, 2008

Hi.

I building some reports with SSRS, and showing data in a table. The table has one Details row that forms at the end multiple rows with the tree view (+ and -).

Is there a way to open the tree view upwards and not downwards so that the children of level 2, 3 etc come over the parent row?

I've goggled it everywhere, but I don't seem to find the answer. If anyone could help me out, I would appreciated.

Thanks
Novi

View 2 Replies View Related

MS SQL Server Tree Structure

Sep 11, 2007

Can anyone please help me? I need to create a tree structure of my company's database server. I need to include all the tables and their description in a tree structure. The output can be in any format. Is there some tool in the MSSql that will do this for me, so I don't have to write it out manualy?? Thank you very much for any ideas!!
M.

View 5 Replies View Related

Decision Tree In MS SQL Server

Jun 28, 2007

Hi,



Can we represent the Decision Tree in a programatically way in an .NET application? I understand that the outcome of a Decision Tree model can be integrated into an .NET application but not sure if we can also visualize it. Does MS SQL Server support any API to render such a tree?



Thanks a lot!

View 3 Replies View Related

Hierarchy Tree In Sql Server

May 15, 2008



Hai


do we have hierarchy query in sql like connect by prior in oracle to dispaly values in tree structure


Help needed

Tahnks in advance
Sumathi.s

View 4 Replies View Related

Recursive/Tree Queries In SQL Server.

Feb 18, 1999

Dear fellows,
Can anybody tell me how can i apply recusive/Tree query using select
statement.
For example I've a table structure for an Organization as follows:

TableName: Employee_tbl
Fields: emp_id, emp_name, supervisor_id

emp_id emp_name supervisor_id
---------- --------------- -------------------
101 ZAFIAN
102 BRUNNER 101
108 CALLAHAN 102
105 RUSSO 102
110 SIM 102
103 DUELL 101
and so on

1. How can I get the above records in Hirarchical format starting from top
or from anywhere else in the hierarchy?

In Oracle it can be done as follows:
SELECT emp_id,emp_name,supervisor_id
FROM employee_tbl
CONNECT BY supervisor_id = PRIOR emp_id
START WITH supervisor_id is null;

Please reply me at the following address if possible:
faisal@visualsoft-inc.com

View 1 Replies View Related

SQL Server 2012 :: Traversing Down A Tree

Feb 9, 2015

I'm working with a development bug database where if someone puts in a bug number, they want to get the parent bug. No problem.

SET @cur_parent = (SELECTdupeof_key
FROMqds.dbo.Dimduplicates d
WHEREd.dupe_key = @checkbug
ANDd.end_ts IS NULL)
WHILE @cur_parent IS NOT NULL

[Code] ...

However, now they want to be able to do the same thing in reverse. Put in a bug and determine how many bugs are duplicates (either directly - children, or indirectly - grandchildren/great-grandchildren, etc.).

The majority of bugs go no more than three generations deep but there are some that go much deeper so I need to have something where I can loop through each potential generation and get the number of bugs associated with it.

Example.

Parent Bug Child Grandchild GGChild
1 2 3 4
1 5
1 28 32
1 40 41 42
1 50
1 60
1 65 70

If I put in bug 1 I should be able to get a count of 13 associated duplicate bugs. Additionally, they want to be able to get a list of the bugs that are associated with that parent.

If there were a set number of levels, self-joining would work to create a generational matrix. However, as there is no limit on how deep the generations can go, I need something dynamic to traverse the tree and generate the list of bugs/count of bugs.

It was easy going up the tree because there was a strict one-to-one relationship between child and parent.

View 9 Replies View Related

Tree View With A SQL Server Database

Jul 20, 2005

We need to present hierarchical data on a web page, the same way thetree view shows files in Windows Explorer. Here's the catch: thattree view needs to be bound to a SQL Server database. How can this bedone?

View 3 Replies View Related

SQL Server 2008 :: Export Tree Data To XML

Feb 23, 2015

I am trying to output the hierarchical data of a tree to xml format.

I can query the data from the tables into a friendly format like this:

create table dummy
(
id int,
childname nvarchar(max),
parentid int,
parentname nvarchar(max)

[Code] ....

And I always know the root ID from the first record on "table" dummy (generated with a common table expression), in this case it's ID 1, but from here, how to process this for any level of depth ?

View 6 Replies View Related

SQL Server 2012 :: How To Copy Nested Sub-tree From One Node To Another

May 12, 2015

I have a tree and I need to copy a nested sub-tree (an element with its children, which in turn may have their owns) from one place to another.

The system should allow to handle up to 8 levels. I do know how to move, but cannot figure out how to copy.

Below is a working example With Create Table, Select and Cut / Paste (implemented via Update).

I would like to know how to copy a nested tree with reference id 4451 from Parent_Id 1 to Parent_Id = 2

--***** Table Definition With Insert Into to provide some basic data ****

IF (OBJECT_ID ('myRefTable', 'U') IS NOT NULL)
DROP TABLE myRefTable;
GO
CREATE TABLE myRefTable
(
Reference_Id INT DEFAULT 0 NOT NULL CONSTRAINT myRefTable_PK PRIMARY KEY,

[Code] ....

How to Copy nested sub-tree 4451 with all its children to Parent_Id 2, without deleting from Parent_Id = 1 ?

View 7 Replies View Related

Possible To Speed Up The Decision Tree By Clustering The Server 2003

Aug 24, 2007

Dear All,


I have a dataminig programming that need to run for days. Is it possibile to speed up the training process by clustering several server by Windows 2003 clustering services? Is it actually that clustering 2 QUAD core computer is almost giving comparable performance as the sum of the speed of two (There must be some overhead, I know). I am actually familiary with the use of clustering. Is it just for making the server farm more reliable or it will collaborate and speeed up the whole training process?

If it is, is there any limit on the number of cluster is in the cluster. What version of Windows and SQL Server do I need to achieve speed up of data mining training process?

Thanks and regards

Tony Chun Tung Siu

View 3 Replies View Related

FileGroup Structures

Apr 14, 1999

I have 2 test database identical in size and table structure, only one resides on filegroups and one resides on a single file.
From everything I have heard filegroups are suppose to improve performance. I stop and start the server before each test to clean out
cache. When I run the filegroup test initially the first run averages 20 seconds slower then the database sitting on the single file. However
on consective runs there is a significant improvement in performance with filegroups verses single files. I have
the indexes sitting on a separate filegroup and 2 additional filegroups to spread the tables across. Does any one know what would be causing
the performance to degrade on the initial run of the test. (The test by the way is a stored procedure that runs a select statement against each table).

Any Info Will help Thanks
Barb

View 3 Replies View Related

Data Structures

Nov 14, 2006

(Wow; surfing this site has really illuminated what a lowly hack-programmer I am to this field of SQL and relational processing :S )I am creating a temp table, doing an Bill of Material explosion for a single Order Line Item.(note: SQL Server 2000)I used blindman's "accumulator method (click here) (http://www.dbforums.com/showpost.php?p=6239109&postcount=6)" to generate the entire potential BOM tree.So; step 1 works wonderfully! :beer: Cheers blindman!Now; I want to remove unwanted nodes (and all their children) from the temp-table. I have a bunch of functions (0 to 1 for each node) that return a Yes or No. If "No", then flag-to-eliminate immediately that branch and don't revisit anything on it (and therein lies my problem). This will leave me with a temp table of only valid nodes.Since this is recursive, and since it will involve Dynamic SQL (the function name varies), all I can come up with is using a Cursor in a WHILE loop. Even at that; since a CURSOR is point-in-time (ie: values don't change once selected), I'll have to re-check the current temp table values (or create of 2nd temp table of only deleted nodes and repeat a SELECT with NOT EXISTS in it, hmmm).Since blindman's method generates a table ordered by level, the sequence of processing is pre-determined - unless I can re-order it into a more traditional hierarchy (1 entire branch at a time) and number the levels, in which case the cursor could just skip to the next branch of equal or higher level.Note: The thought does occur to me I could have an intermediary function (static name) that in turn does the Dynamic SQL. These functions contain the Business Logic that looks at a myriad of column values and relationships in the database and there's no one-size-fits-all decision tree so Dynamic SQL is necessary.The max cursor size will be maybe 300, and on average 100. Number of levels will normally be 3 or 4, but conceivably could be up to 10. Given the average 100 potential components/sub-assemblies, the final assembly will be about 30. As a periodic background process; it will do 3,000 Order Line Items a day, so I'm figuring 1 second response time per build is adequate (ie: the user's not waiting on it so it doesn't have to be blinding fast) - however why waste?Anyhow; I thought this might be a fun problem for some Data Structure genius who wants to give a lesson in Relational Programming.Thanks for looking.Here's what I have so far:CREATE PROCEDURE dbo.sp_ExplodeTest1 (@recID int = 1) AS/* tbTestH is a table containing an assembly hierarchy. Assemblies with no parent are Builds.Assemblies with no children are Components.It's columns: MyID int, ParentID int, (other descriptive columns)*/declare @t table (TempNodeID int identity(1,1),MyID int)-- Seed the tree with the Build's ID.insert into @t (MyID) values (@recID)/* This populates the temp table with the entire Assembly for the given build. It is Ordered By the level in the assembly. Number of assembly levels is infinite.For example: Level 1 = the Build. It comes firstLevel 2 = all parents are level 1. Is next (no particular seq)Level 3 = all parents are level 2. Is next (no particular seq)etc.*/while @@Rowcount > 0insert into @t (MyID)select tbTestH.MyID from tbTestHinner join @t rList on tbTestH.ParentID = rList.MyIDwhere not exists ( select *from @t CurrentList where CurrentList.MyID = tbTestH.MyID)-- now to display the results so far.select t.*, tbTestH.* from tbTestH inner join @t t on tbTestH.MyID = t.MyID order by t.TempNodeIDGO

View 8 Replies View Related

SQL Data Structures

Aug 9, 2007

What is included under SQL Data structures? Could anyone refer me to some good tutorials on that material?

View 2 Replies View Related

Mining Structures

Aug 23, 2006

I am using the wizard to create a new mining structure and getting the error at the time of selecting the datamining technique like either microsoft decision tree or microsoft timeseries etc.,

"Unable to retrieve a list of supported data mining algorithms. Make sure you are connected to the correct Analysis Services server instance and the Analysis Services server named localhost is running and configured properly. You can continue with a default list of data mining algorithms."

What is that means?

Thanks in advance,

View 3 Replies View Related

Printing Out Table Structures......

Nov 15, 2000

I have a SQL 7 database with about 30 tables in. For documentation purposes I need to print out the structures of each table. I have tried using the diagram tools but no joy.

I have access to Access, Crystal Reports, if these are any use?

Please help!!

Tony Kavanagh

View 3 Replies View Related

Tools For Db Structures Comparision

Jul 10, 2002

Hi,Does any of u folks used any tools for database structures comparision??

I have used DBDIFF(from DKGAS.com) ChangeManager from Embarcadaro and SQL COMPARE from Redgate.

I did have have some problem in each of these tools AND am looking for some good tools which are economical also.

Thx in advance
Ravi

View 2 Replies View Related

Complex Data Structures

Oct 5, 2001

A point for general discussion maybe.

I've just read Jeff's query regarding passing an array to a stored procedure, and it seems to be a question that hits the message board quite frequently. There often seems to be the case where you have some block of data in one location, and want to process it somewhere else, and there just isn't an easy way to do it (or is there?). Passing a cursor is possible, but getting data back out of a cursor is painful.

The ways I have used in the past are:

Using a cursor
Using a global temporary table
Using a "permanent" table, but declared with a unique name (using a timestamp) and passing the tablename as a parameter.

Has anybody any suggestions for a future SQL release which we could suggest to Microsoft?

Suggestions from myself:
-Having a single TSQL command to copy a cursor back into a table, to make cursor parameters less cumbersome
-Being able to pass a pointer to a temporary table as an SP parameter
-Allowing variables to be declared with more complex structures (such as arrays, or classes)

Regards,
ChrisH

View 1 Replies View Related

Table Structures Script

Dec 11, 2006

I will soon be writting a script which will search threw all tables in my database and try to find how they may be linked to one another, and also which tables are called by which stored procedures, any suggestions or tips would be great.

View 1 Replies View Related

Rendering Directory Structures

Oct 31, 2005

Hi, I have a table of folders that I would like to be able to displayin a depth first manner, similar to what you would see in WindowsExplorer. the table is defined similar toCREATE TABLE Folders (folderID int,parentFolderID int,name varchar(32)).... I've left some things out of the definition for the simplicity ofexample.My desire is to quickly generate a record set containing the all childfolders of a specific folder along with the how many levels deep eachfolder is, in a quick and memory efficient manner. I have done someresearch through this group and found a few examples similar to what Ihave hypothesized, however I was hoping for some feedback on what Ihave decided to use.Since this database table is already created and I cannot modify theexisting schema, it would not be very feasible to use a nested setsmodel (unfortunately -- or if anyone has a suggestion?).I plan on using a stored procedure that recusively calls itself.something similar to the following:/* This is assuming the table #TempFolderTable has* already been declared globally*/sp_FolderDisplayRecurive @folder int, @level int ASIF @@NESTLEVEL > 31 RETURN;DECLARE @childFolder INTDECLARE folders_cursor AS CURSOR LOCAL FORSELECT folderID FROM FoldersWHERE parentFolderID = @folderIDOPEN folders_cursorFETCH NEXT FROM folders_cursorINTO @childFolderwhile @@Fetch_status = 0BEGIN-- Insert current folder into-- folder table (under parent @folder)INSERT INTO #TempFolderTable(FolderID, DepthLevel, ParentFolderID) VALUES(@childFolder, @level, @folder)-- Iterate over all of its childrenEXEC sp_FolderDisplayRecursive@childFolder, @level + 1FETCH NEXT FROM folders_cursor INTO @childFolderEND...Will this incure a large overhead for a deep directory structure? Arethere any other problematic issues? Any suggestions and/or commentsare very welcome. Thanks!

View 3 Replies View Related

How To Compare Database Structures?

Jul 20, 2005

Let us suppose that I have two similar databases and need to create ansql-script upgrating one database structure to another. For example, thesedatabases are from different versions of some software, first is from earlyversion, next is from current, and second one contains several new tables,sevelal new fields in old tables, several new or changed stored procedures,UDFs and so on.How to solve this problem using standard tools?

View 6 Replies View Related

Comparing Table Structures.

Oct 18, 2006

Hi all,

Could anyone let me know if there are any Scripts available for comparing the schema differences between two SQL server databases?

Thanks

DBAnalyst



View 2 Replies View Related

Compare Tables Structures

Apr 1, 2008



Hi All,

I have 2 tables in different database. I need to compare the tables structure and insert the fields if not existing.

Ex:

I have 3 fields in table1.(database name Pubs)

Table1
F1
F2

F3

I have 2 fields in table2.(database name northwind)

Table2
F1
F2


I need to insert the table1.F3 into Table2. Basically i need to compare all the fields with table1, if not exist in table1 i need to insert that field into table2. I am using SQL Server 2000. Please send me the code.

Thanks,
Mears

View 7 Replies View Related

Open Source DB Structures

Oct 27, 2006

I'm wondering if anyone knows of a good site to find open source database structures (such as ERD's, scripts, or something of that nature)?

I think I have a pretty good handle on database design, but it would be nice to have a resource like that so that I can compare the design of my DB to DB's that people (smarter and more experienced than me) have created for similar purposes.

What I'm thinking of is a site like Open Source Web Design (www.oswd.org) for Databases. Anyone know of anything?

View 1 Replies View Related

Changing Database Structures Through Code

Apr 28, 2006

I am having a hard time finding materials on this subject.  I am guessing I am using the wrong keywords to search.  Basically, I want to be able to modify database tables through a web form.  They can add columns and delete columns through the form.  I would just want to default the type of column and the length.  I am sure it has been done, I was just wondering if anyone had some resources they could throw my way.  I would appreciate it.  Thanks.

View 1 Replies View Related

Merging Two Databases With The Same Table Structures

Oct 20, 2000

Hi
I have a problem out here. I have two databases with the same table structure
and I want to merge data from both the tables . Please can anyone let me know.
Iam using Sql Server 7.0.

Thanks
Bye

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved