简体   繁体   English

具有参数数据库名称的存储过程?

[英]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. 我可以想象,我可以将此存储的proc放在另一个中央数据库中,并将其传递给变量1。

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. 现在,它正在C#/ ASP.NET中执行动态SQL,方法是使用DB脚本获取文本文件并替换其中的文本变量。 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 动态SQL

  2. IF-based handling: 基于IF的处理:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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