Home All Groups Group Topic Archive Search About

Sql Management Studio - Script Db creates objects out of ourder

Author
16 Jan 2007 7:09 PM
Andrew Robinson
Don't know if this is the best place to post this but I have a db with about
100 tables and a number of views and sprocs. When scripting the entire db
using SMS, a number of the views and sprocs are created before their
associated underlying tables are. Can anyone shine a bit of light on this
issue? I am guessing that it is a common one since I have seen it a number
of times.

I have also tried the new Database Deployment Wizard RC and it generates
scripts with the same issue. Guessing that maybe this has something to do
with my db?


Thanks,

Author
16 Jan 2007 7:21 PM
Aaron Bertrand [SQL Server MVP]
> Don't know if this is the best place to post this but I have a db with
> about 100 tables and a number of views and sprocs. When scripting the
> entire db using SMS, a number of the views and sprocs are created before
> their associated underlying tables are. Can anyone shine a bit of light on
> this issue? I am guessing that it is a common one since I have seen it a
> number of times.
>
> I have also tried the new Database Deployment Wizard RC and it generates
> scripts with the same issue. Guessing that maybe this has something to do
> with my db?

In the short term, I would suggest creating the tables first, and then
creating the objects that interface with them.

Other than that, I would check connect.microsoft.com/sql/ for a reported
issue, and either vote or file a new one.

A
Author
16 Jan 2007 11:09 PM
Erland Sommarskog
Andrew Robinson (nemoby@nospam.nospam) writes:
> Don't know if this is the best place to post this but I have a db with
> about 100 tables and a number of views and sprocs. When scripting the
> entire db using SMS, a number of the views and sprocs are created before
> their associated underlying tables are. Can anyone shine a bit of light
> on this issue? I am guessing that it is a common one since I have seen
> it a number of times.
>
> I have also tried the new Database Deployment Wizard RC and it generates
> scripts with the same issue. Guessing that maybe this has something to do
> with my db?

Scripting depends on the dependency information in the database. Given the
flexible nature of SQL Server, this information may be incomplete. If you
create a table nissetbl, and the a stored procedure kalle_sp that refers
to nissetbl, SQL Server with store information about this. But if you
now drop and recreate nissetbl, this information is lost. When you recreate
nissetbl, it would be kind of expensive to examine 5000 stored procedures
to see if they might refer to nissetbl. Also, keep in mind that SQL Server
to permits you to create kalle_sp before nissetbl exists at all.

Thus, the only way to get you generated script correctly is to generate
the database correctly from the beginning. ...or at least it was up to
SP2 of SQL 2005, which introduces a system procedure, sp_refreshsqlmodule
which updates the dependency information for a stored procedure or
similar.

SP2 for SQL 2005 has not been released yet, but a preview (aka CTP) is
available.


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button