March 19, 2003 at 10:12 pm
I'm new in SQL Server 2000. I am studying for taking SQL Server certification. How to create an array in SQL Server 2000.
One more question how to create a tree in SQL server 2000
March 19, 2003 at 10:37 pm
SQL Server doesn't support arrays. You could simulate this with a table datatype or temp table or perhaps a cursor.
For a tree, there are multiple ways. Is this a tree with 2 nodes for each branch (binary tree) or other type of tree?
Steve Jones
March 20, 2003 at 4:07 am
Remember that the idea behind the set orientated way of SQL is very different from 'normal' programming. Probably you do not need arrays or trees. But if you really do listen to Steve Jones 🙂
Regards, H. Lindgren!
March 20, 2003 at 10:04 am
Ha, don't know about that.
SQL tends to work with a group of rows rather than a single row. None of the datatypes map well to an "array" structure.
Might change in Yukon, but in 2000, the closest is the table datatype or another I thought of. An XML stream in a text or varchar column. You could build a routine to store an XML "array" like this.
Steve Jones
March 20, 2003 at 11:24 am
Although there are ways to simulate arrays in SQL Server, the best advice and solution imho would be to think about whether you really need an array. Often you are just thinking like a programmer, not a DBA.
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
March 20, 2003 at 11:38 am
Thanks enerybody. anybody please give me an example how to create an array. It's binary tree. I want to go to lower node, delete the node and add to the higher node. I wasn't able to make this type of tree. For example, The company has manager and employee relationship. I want to name of manager who contains particular number of employee.If I enter two, result will return the name of managers who have two employee.
Thanks.
Shraddha
March 20, 2003 at 8:54 pm
Not only are you still thinking like a developer, but you are ignoring some very
sound advice from some knowledgeable people. At least about sql server anyway,
they may not know how to tie their own shoes, but about sql server they are
not going to steer you wrong. I think you have some misconceived ideas about
what sql server is capable of. Sql does not support hash tables, arrays, linked
lists, binary trees, pine trees, etc... To accomplish what you wish you will
either need to do a scrollable cursor, a series of set based statements, or pull
the data back and manipulate it on the client.
Tim C.
//Will write code for food
Tim C //Will code for food
March 20, 2003 at 9:13 pm
I think he is talking about a hierarchical structure. A father / son relationship table of some sort, bill of materials. 1 Bicycle -> 1 frame -> two wheels -> 20 spokes, tyre, etc.
March 20, 2003 at 9:15 pm
Yeah! That's right. Would you give some idea how to implement it.
March 20, 2003 at 9:38 pm
Chrhedga, do you imply sequential / asynch versus set based?
March 20, 2003 at 9:58 pm
Thanks, I solved my problem.
March 21, 2003 at 1:39 am
quote:
Chrhedga, do you imply sequential / asynch versus set based?
Absolutely not (and I think you didn't mean I did judging by your smiley). First of all, in order be become certified in SQL Server you definately don't need to know how to simulate an array in SQL Server. If you are thinking of arrays then you should probably think of remodeling your design.
Regarding trees, yes I know of Celko's Nested Sets model, Itzik Ben-Gan's Enumerated Paths model and Steve Kass' Access Paths model. They are all way better than a recursive and/or cursor based implementation of traversing a tree since they are all set based, but still you need to think about if you really need a tree. Remember, SQL is relational (more or less), not hierarchic.
Tim, I wear boots without shoelaces so I'm alright there.
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply