开发者

How to pass database name into stored procedure?

开发者 https://www.devze.com 2023-02-25 19:54 出处:网络
How to pass database name into stored procedure? I tried something like create procedure dbo.Test @databaseName varchar(100)

How to pass database name into stored procedure? I tried something like

create procedure dbo.Test
    @databaseName varchar(100)
as
select * from @databasename开发者_如何学JAVA.Person.Address
go

I would like to use it like this

execute dbo.Test @databaseName = 'AdventureWorks'


This is not possible in the manner you are describing.

You can do this with dynamic SQL, but that brings its own set of problems.


Sounds like you are trying to move information which should be part of connection string into stored procedure logic. If you expect that Person table will be in different database this database name should be fixed in deployment - for example by parametrized creation script and sqlcmd.

0

精彩评论

暂无评论...
验证码 换一张
取 消