Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
>>>>Hi
>>>>
>>>>I want to pass a database name into my stored procedure and then use that database for everything that the stored procedure does.
>>>>
>>>>Whats the syntax for that ?
>>>>
>>>>Thanks
>>>
>>>You must use so called Dynamic SQL.
>>>BTW why you need this?
>>>If you call Database SP it will be executed for that DB, no matter to which DB you are connected.
>>
>>Hi Boriss
>>
>>I wanted to have a stored procedure in one database that could optionally be run against several other databases so I could pass in the database as a parameter.
>>
>>
>>So I can't do that ?
>>
>>I have to have the stored procedure in the database its to run on ?
>>
>>Thanks
>
>Making one 'generic' SP that works for everything is against the good practice in SQL Server. Dynamic SQL is not something that should be used freely.
I'm developing a stored procedure in a test database and I would have liked then to have pointed it at the "live " database, instead I have to create the stored procedure in the live database.
As usual "best practise" is something other than what I want to do.
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement