在存储过程中创建数据库,可以用变量做为数据库名吗?
在存储过程中创建数据库,可以用变量做为数据库名吗?
如:
create procedure createdb (@dbname varchar(30))
as
begin
create database @dbname
end
------解决方案--------------------create procedure createdb (@dbname varchar(30))
as
begin
exec sp_executesql N 'create database '+@dbname
end
------解决方案--------------------不行你就换个写法好了
create procedure createdb (@dbname varchar(30))
as
begin
exec ( 'create database '+@dbname)
end
------解决方案--------------------create procedure createdb (@dbname varchar(30))
as
begin
exec( 'create database '+ @dbname)
end
------解决方案--------------------create procedure createdb (@dbname varchar(30))
as
begin
exec( 'create database ' +@dbname)
end
------解决方案--------------------create procedure createdb (@dbname nvarchar(30))
as
begin
declare @strSql varchar(1000)
set @strSql= 'create database '+@dbname
exec sp_executesql @strSql
end