More complete implementation of the nested set model, with schema, triggers, stored procedures, and get-ers.
How to get started
Create Entities.sqlin your favorite playground SQL database. It will create the schema
nsm, the base
table, and the friendly
Sample Data.sqlin said database to fill the new table with some data.
- Run the
trg_scripts to create the triggers.
MoveCatSubtree.sqlto create the stored-procedure that moves nodes/subtrees around. a. In re-thinking about this project, it should probably be called "ChangeCatParent", but I'll get to that renaming later.
Trying it out
- Check out the
Sample Queries.sqlto see some SELECTs in action.
Sample Data.sqland run the comment-blocked INSERTs at the bottom.
- Write your own INSERT/UPDATE/DELETE queries to build your favorite family of cats!
I welcome any feedback, pull-requests, issues, suggestions, and rants! Leave a comment on my blog (natethedba.wordpress.com), and of course, stalk me right here on GitHub!
Compatibility: MS SQL Server 2008R2 & higher.
I ask politely for attribution if you found these scripts helpful, but I'd settle for an upvote on StackOverflow and/or a comment/follow on my blog! Cheers.