Recursive CTEs and Bill Of Materials problem (part two: cyclic references)

Sergio Govoni

Nel precedente post Recursive CTE and Bill Of Materials problem abbiamo descritto una CTE ricorsiva nel tentativo di risolvere un problema del mondo reale, ovvero l’esplosione scalare a tutti i livelli della distinta materiali di un prodotto fornito in input.

Prima di realizzare la CTE ricorsiva CTE_BillOfMaterials abbiamo ipotizzato che le distinte materiali memorizzate nelle tabelle Production.BillOfMaterialsHeader e Production.BillOfMaterialsDetail avessero tutte una struttura ad albero aciclica (come è nella realtà). Alcune volte, le ipotesti più credibili non vengono verificate sui dati in produzione, ed è stato così, si è semplicemente assunto che l’ipotesi fosse vera. Durante il deploy della CTE, però, ci siamo accorti che questa ipotesi non era verificata per tutte le distinte memorizzate. Accadeva, di tanto in tanto, che gli utenti lamentassero un errore durante il tentativo di esplodere la distinta di un prodotto. Il seguente errore, che si verificava solo per alcuni prodotti, poteva essere il sintomo di un problema nei dati:

SQL Server 2008 R2 Update for Developers Training Kit

Davide Mauri

Aggiornamento del Training Kit per tutti gli sviluppatori che utilizzano SQL Server 2008.

Tra i contenuti:

  • Videos (8)
    • SQL Server 2008 R2 Update for Developers Overview Part I - SQL Server 2008 Review
    • SQL Server 2008 R2 Update for Developers Overview Part II - Introducing SQL Server 2008 R2
    • Introducing SQL Server 2008 R2 StreamInsight
    • Demo: Real Time Analytics with SQL Server 2008 R2 StreamInsight
    • Introducing SQL Server 2008 R2 Application and Multi-Server Management
    • Introducing SQL Server 2008 R2 Reporting Services
    • Introduction To SQL Server 2008 R2 StreamInsight and Complex Event Processing
    • Introducing PowerPivot for Excel 2010 and SharePoint 2010
  • Presentations (8)
    • SQL Server 2008 R2 Update for Developers Overview Part I - SQL Server 2008 Review
    • SQL Server 2008 R2 Update for Developers Overview Part II - Introducing SQL Server 2008 R2
    • SQL Server 2008 Filestream
    • SQL Server 2008 Spatial
    • SQL Server 2008 T-SQL
    • SQL Server 2008 Date and Time Types
    • SQL SErver 2008 SQLCLR
    • SQL Server 2008 Reporting Services
  • Demos (13)
    • AdventureWorks Racing All-Up SQL Server 2008 Demo
    • SQL Server 2008 All-Up Spatial Demo
    • SQL Server 2008 Spatial Types Demo
    • Intro to SQL Server 2008 Filestream Demo
    • SQL Server 2008 SQL CLR Nullable Types Demo
    • Programming with SQL Server 2008 Filestream Demo
    • SQL Server 2008 Reporting Services Web Application Integration Demo
    • Date and Time Support in SQL Server 2008 Demo
    • SQL Server 2008 T-SQL Table-Valued Parameters Demo
    • SQL Server 2008 T-SQL Row Constructors Demo
    • SQL Server 2008 T-SQL Grouping Sets Demo
    • SQL Server 2008 T-SQL Merge Demo
  • Hands-on Labs (8)
    • How to build your first Web Application with SQL Server and ASP.NET
    • Using SQL Server 2008 Spatial Data in TSQL
    • Using SQL Server 2008 Spatial Data in Managed Code
    • Using SQL CLR in SQL Server 2008
    • PowerPivot in SQL Server 2008 R2
    • Using the New Features of Reporting Services 2008 R2
    • Introduction To SQL Server 2008 R2 StreamInsight and Complex Event Processing
    • Data-tier Applications in SQL Server 2008 R2 and Visual Studio 2010

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=fffaad6a-0153-4d41-b289-a3ed1d637c0d

Una soluzione basata su T-SQL per la manutenzione dei database

Davide Mauri

E’ risaputo che per la manutenzione degli indici di database di grandi dimensioni è opportuno lasciare perdere il Maintenance Plan messo a disposizione dal Management Studio (SSMS), e intervenire mediante Job T-SQL che realizzino una manutenzione più mirata. Lo stesso vale per le altre attività di manuntezione più tipiche quali il controllo dell’integrità del database, l’aggiornamento delle statistiche e il backup.

Recursive CTE and Bill Of Materials problem

Sergio Govoni

CTE, dalla versione 2005 di SQL Server, è l’acronimo di Common Table Expression. Una Table Expression è una tabella derivata, completamente virtuale, originata da una query. Una tabella derivata può essere citata nella clausola FROM come una qualsiasi altra tabella fisica. La visibilità di una tabella derivata è limitata alla query esterna della CTE.