More complete implementation of the nested set model, with schema, triggers, stored procedures, and get-ers.
- Run
Create Entities.sql
in your favorite playground SQL database. It will create the schemansm
, the basetable
, and the friendlyview
. - Run
Sample Data.sql
in said database to fill the new table with some data. - Run the
trg_
scripts to create the triggers. - Run
MoveCatSubtree.sql
to 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.
- Check out the
Sample Queries.sql
to see some SELECTs in action. - Revisit
Sample Data.sql
and 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.