Hi all,

Anyone know how to create a data base gives the name of the same parameterized?

Example in a store procedure, named 'x', which has a parameter, this will do since the create dabase @variable

create procedure creadatabase
@db_name varchar (10)
as
create database @db_name
go

But this variable throws syntax error

That's what I try to do but I could see how it does.

Thnks a toto everybody

You can use the "EXEC" statement in your procedure to dynamically build the necessary statement.

create procedure creadatabase
@db_name varchar (10)
as
exec('create database ' + @db_name)
go

That being said, you might consider carefully before you allow just anybody to run this procedure. The possibility of people creating databases willy-nilly could turn into a DBA's nightmare (and I speak from experience on this!)

commented: The less interaction from average user the better +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.