Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to create database using variables instead of database name and file name.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-24 : 01:13:30
Ian writes "Hi SQLGuru,
My question is: Can I create database script using variables? So far I had no luck. I hope you can help me with it.Below is my statement.
Thank you in advance, Ian.

USE MASTER
GO
Declare @DBname varchar (30), @DBfile varchar(225)
SET @DBname = 'Knowdev_Site2'
SET @DBfile = 'c:\program files\microsoft sql server\mssql\data\'
CREATE DATABASE CAST(@DBname AS varchar(30)) ON
( NAME = CAST(@DBname AS varchar(30)),
FILENAME = CAST(@DBfile as varchar(225)) + CAST(@DBname AS varchar(30)) + '.mdf',
SIZE = 100MB,
FILEGROWTH = 20)
LOG ON
( NAME = @DBname,
FILENAME = CAST(@DBfile as varchar) + CAST(@DBname AS varchar(30)) +'.ldf',
SIZE = 100MB,
FILEGROWTH = 20)

GO"
   

- Advertisement -