Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A <a href="http://msdn.microsoft.com/en-us/library/ms190019%28v=sql.105%29.aspx" rel="noreferrer">Partitioned View</a> is something I had no experience with prior to this question. Using the definition provided in the linked article, I came up with this <a href="http://sqlfiddle.com/#!3/2f489/2/0" rel="noreferrer">schema and a sample insert</a> to verify I knew I was doing.</p> <p>I rolled the transaction back so I had no data in my <code>dbo.Year1998Sales</code> view. I then created a new SSIS package. The fact that I used SSIS for SQL Server 2012 will have no bearing on the results, the configuration will be the same.</p> <p>I created a new package, added a data flow, added an OLE DB Connection Manager and within my Data Flow I have an OLE DB Source wired to an OLE DB Destination.</p> <p><img src="https://i.stack.imgur.com/odlCz.png" alt="enter image description here"></p> <p>In my source, I used the same query as in my SQLFiddle demo</p> <pre><code>SELECT D.number AS OrderId , D.number * 100 AS CustomerID , DATEADD(D, d.number % 365, '1998-01-01') AS OrderDate , 1+ (D.number % 12) AS OrderMonth , DATEADD(mm, (D.number % 12), '1998-01-01') AS DeliveryDate FROM ( SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) -1 AS some_number FROM master.dbo.spt_values AS SV ) D (number) ORDER BY D.number ASC; </code></pre> <p>I selected <code>dbo.Year1998Sales</code> as the destination and viola, it works. Actually no, it didn't to my amazement. What worked within SSMS errors out in a data flow.</p> <blockquote> <p>[OLE DB Destination <a href="http://sqlfiddle.com/#!3/2f489/2/0" rel="noreferrer">2</a>] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Partitioned view 'FOO.dbo.Year1998Sales' is not updatable as the target of a bulk operation.".</p> </blockquote> <h1>Resolution</h1> <p>The telling portion of this error message is the "target of a bulk operation." A Data access mode of <code>Table or view - fast load</code> or <code>Table name or view name variable - fast load</code> will result in a bulk insert into the table and <em>generally</em> speaking that is something you will want. However in this case, that isn't possible so one must use the RBAR (row by agonizing row) version of a destination <code>Table or view</code> or <code>Table name or view name variable</code>.</p> <p>That does work and for smaller data sets, that would be my approach.</p> <h2>Alternative 1</h2> <p>Completely bypass the logical construct of the view and recreate the logic with a conditional split and write to N tables. This would allow you to use bulk updates to the table. However, there's a not insignificant cost associated with replicating that business logic into your package and further maintenance on the package to keep the two in sync. Heaven help you if the logic gets changed in the underlying view and those changes aren't propagated to the package or ported incorrectly. I would not go this route unless I had a bullet-proof business reason for doing so.</p> <h2>Alternative 2</h2> <p>Stage your data. Instead of writing to the partitioned view, write all the data to a staging table in the data flow. Immediately after the data flow, have an Execute SQL Task that pushes the data from the staging table into the View. </p> <p>While I don't know for certain, my assumption is that this will perform better than Alternative 1 or the original resolution but have not tested. I also don't list this as the primary resolution because I know in some places, like where I work, creating a new table can be rather controversial. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload