Saturday 28 July 2018

When does a SQL Table think it's a View?

Try this one out:
  1. Create a SQL database
  2. Create a couple of tables
  3. Create a view that queries those tables and make sure to include a calculated column
  4. Create an empty table from the view using SELECT INTO...WHERE 1=0
  5. Drop the view
  6. Rename the empty table to the name of the dropped view
  7. Try and insert some data into the table
  8. Scratch your head...
Yup, SQL still thinks the object with the same name is a view and because it includes a calculated column it won't let you insert data into it.

To solve the issue, execute the sp_refreshview proc using the name of the new table.

What a SISS-up!

Have you ever had the situation where you have set up automated deployment of a SSIS package and you upgrade the package and the SQL Server it is deployed to, then suddenly your packages start behaving weirdly?

Well believe it or not it can happen that you are able to deploy a SQL Server 2016 package to a SQL Server 2016 server using a 2014 SSIS deployment wizard and get no exceptions during deployment. Then your packages start misbehaving, like simply missing out script tasks and completing successfully. I kid you not!

So, there lesson here is that just because it deployed successfully using the wrong wizard, don't assume it will work correctly.