Why would the SQL 2008 "Generate scripts..." utility generate an invalid SQL script?
- by Deane
I have a SQL2008 database that needs to be restored to a SQL2005 instance.
I have gone through the "Generate scripts..." wizard, set it for SQL2005 compatibility, and generated a 62MB SQL script.
When I run it on the SQL2005 instance, it throws all kinds of errors, and some of them are really strange in that they describe an invalid database.
FK constraints are wrong. It's trying to create FKs on columns that don't exist.
It's trying insert records with duplicate key errors.
It's trying to create the same objects twice.
Any idea how this could happen? This SQL script was generated by SQL Server Management Studio just minutes before I tried to restore it, and was not modified.
Why would this generate an invalid SQL file? Doesn't it just describe the SQL2008 database, which is presumably valid since we're using it?
In particular, the duplicate key insertion errors mystify me. If there's a key constraint in the SQL script, then there must be the same thing in the SQL2008 table. So how could we get rows in there that violate that key constraint?