Why would the SQL 2008 "Generate scripts..." utility generate an invalid SQL script?

Posted by Deane on Server Fault See other posts from Server Fault or by Deane
Published on 2010-04-09T15:21:04Z Indexed on 2010/04/09 15:23 UTC
Read the original article Hit count: 393

Filed under:
|

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?

© Server Fault or respective owner

Related posts about sql-server

Related posts about sql