SQL Server Hierarchical Queries - CTE vs JOIN (Parent Child , Category Subcategory)

Опубликовано: 03 Октябрь 2024
на канале: Geekus Maximus
1,574
22

This video tutorial introduces two methods for querying hierarchical data in MS SQL Server. One common method for doing so is via Common Table Expression queries, while the other method utilizes multiple self joins. Both T-SQL Query methods are compared side by side on a table containing over 2 million rows of Category Subcategory arraignment within the same table referencing a category ids with parent category ids. Example code written in C#, to generate 2million rows of sample data, utilizes the SQL Bulk Insert method via ADO.Net in DotNetCore (DotNet6). Other SQL tips are included as well as source code and SQL statements where necessary.
This video presumes the viewer already has working knowledge of SSMS (SQL Server Management Studio), intermediate knowledge of the T-SQL language and basic querying (SELECT, JOINs, Aliased tables, and CTE queries), and familiarity with Microsoft Visual Studio and C# to follow along.

Source code for the C# database stuffing (creates categories and subcategories from C#) is available here:
https://github.com/beefydog/DBStuffing

Source code for SQL queries used in this tutorial:
https://github.com/beefydog/DBStuffin...
https://github.com/beefydog/DBStuffin...

If this video helped you out, take me out for a cup of coffee☕
https://www.buymeacoffee.com/geekusma...

Sponsored links (helps to support this channel):

Want a superfast Windows 2019 Server virtual machine on the Cloud, but don't want to pay a fortune for it (or get nickel & dimed by other cloud providers)? I host multiple websites, email services, and SQL databases, on a single SSD driven Win2019 VM with absurd amounts of bandwidth and speed for around $60/month, but you can host pretty much anything for as low as $2.50/month! Same system in competing Cloud companies runs into the hundreds a month for identical service. No contracts! No hidden fees! Full VMs, Containers, DevOps, Backups, Firewalls, Etc.
Click this link to learn more (use my affiliate link to get $0.01 first month of service):
https://www.interserver.net/r/739044
EXCLUSIVE OFFER TO VIEWERS $.01 FIRST MONTH. COUPON CODE : TRYINTERSERVER

If you have a website and want fast, updated, REAL people leads for generating traffic, please visit my lead generation website here:
https://beefydog.com

Need FREE website monitoring? Visit the following link for free and paid monitoring at dirt cheap pricing.
http://trinar.com