Ziff Davis EnterpriseDevLife
Advertisement
Advertisement

Wednesday, January 28, 2009 9:32 AM/EST

SQL Server 2008 Management Studio Script Generation Skips Tables

In my book there are a lot of walkthroughs that depend on my sample database(s). Rather than providing the entire database files, I have been providing scripts for readers to create the databases and data themselves.

SQL Server 2008's SSMS has a script generation wizard that lets you create the database objects (tables, views, etc) as well as the data. It also gives you the ability to target SQL Server 2008 or 2005, which I need to do. But there's a big problem. After I have run the wizard, I find that the script is missing tables. The wizard's checklist shows that they were all created, but the sql for creating a number of the tables is nowhere to be found in the script.

When running the script, it fails when objects depending on those tables are created. If not for this failure, there is no other indication that anything else is wrong (e.g., that required tables were not built).

I have not been able to determine why this is happening. The databases that this has happened with are not even that large.

What I have done to get around it is to build the script in two steps. I run the wizard and create ONLY the tables and their data. Then I run the wizard a second time and create the other objects (views, stored procs, functions, ect). When I have both scripts, I then add the text of the 2nd script to the end of the first.

Additionally, the actual database creation is a separate wizard altogether so I have to add these two to the end of the first script which creates the database.

I have attempted to do web searches on this problem but have not been able to find anything. Generally only instructions for creating scripts come up.

I'm sure I could do this more eaily with Red-Gate's SQLPackager, but I was determined to make SSMS do it's job as advertised.

TrackBack

TrackBack

http://blogs.devsource.com/cgi-bin/mte/mt-tb.cgi/16332

Comments (3)

Great Post. Helped me out with the exact same problem. This seems to be a pretty significant bug with SQL08. Surprised it's there. I wonder what determines what tables get scripted and which ones don't make the cut.

Ken :

After upgrading from SQL 2000 to 2008 the first thing I did was try to re-create the generation scripts using SSMS. Everything LOOKED fine (no warnings, no errors) until I tried using the tables.

Then, I discovered the exact same problem. On 3 of my 9 databases some tables simply were not being generated. Again, as you found, the only solution appears to be to split table creation out into a separate script.

I did find that the behavior differed somewhat depending on whether I clicked the "script everything" check box. SOMETIMES if I did not (and selected everything manually I would get an error: "Operation is not valid due to the current state of the object. (SqlManagerUI" for one of the tables. Sometimes it would just still fail silently.

This is a MAJOR pain, and huge bug that Microsoft needs to address.

BTW, SQL 2000 generated the scripts just fine.

Ken Koch :

This problem was fixed with SP1. It cost me several days to figure that out, but... Anyway, you can now script the entire database with no problems.

Post a Comment

 
 

Advertisement

Syndication

Subscribe: