简体   繁体   中英

Stored procedure with parameter database name?

Is there anyone to call and run a stored procedure with the database name (they are snapshots, one created per client) as a variable passed to the stored proc? The tables themselves are known and won't be variable. I could put this stored proc on another central database and have it reach across to the variable one, I'm imagining.

Right now, it's executing dynamic SQL in C#/ASP.NET by taking a text file with the DB script and replacing text variables inside of it. I'd like to try doing as a stored procedure instead.

If you pass a database name (or any other object name) to a stored procedure, you only have two ways of handling it in the stored procedure:

  1. Dynamic SQL

  2. IF-based handling:

 IF @DataBaseName = 'A' EXECUTE A.dbo.StoredProc ELSE IF @DataBaseName = 'B' EXECUTE B.dbo.StoredProc ELSE IF ... 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM