Posted by David Portas on 12/27/06 19:49
fireball wrote:
> please help newbie
>
> I need to create a lot of objects the same type (let's say: schemas)
> I wish to use paramerized block in loop to do so.
> - how to put names of my objects to such control-flow?
>
>
>
> belss you for help
Firstly the obvious question: Why? Where are the names from these
objects coming from? If you can write a query to extract the names then
you could just use Query Analyzer or Management Studio to paste those
names into an editable script and then run the script directly. That
way there is no need for a loop.
If you must do it programmatically then you'll have to do something
with dynamic SQL. See:
http://sommarskog.se/dynamic_sql.html
Personally I'd say that if you have so many schemas that you need a
loop to create them then you definitely have too many schemas... or you
are using them in a highly unconventional manner.
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Navigation:
[Reply to this message]
|