I have a script that works well with hardcoded values which I am trying to parameterise. I am new to SQL server but thought it must be possible. I've include some code which I thought may work but doesn't.
Basically I want to run the script to create the database and tables. Is this possible? I don't want to do it from a procedure.
Mark Davies
Warwickshire County Council
Basically I want to run the script to create the database and tables. Is this possible? I don't want to do it from a procedure.
Code:
-------------------------------------------------------
-- DECLARE VARIABLES USED IN SCRIPT (added by M.Davies)
-------------------------------------------------------
-- The Database Name
DECLARE @DataBaseName VARCHAR(20)
SELECT @DataBaseName = 'Saw_Live'
-- The database file name
DECLARE @DatabASeFilename VARCHAR(20)
SELECT @DatabASeFilename = 'Saw_Data'
-- The Database Location on the physical server (suffixed with MDF extension, EG. Saw_Live.MDF)
DECLARE @DatabASeFileLocation VARCHAR(250)
SELECT @DatabASeFileLocation = 'E:\Microsoft SQL Server\MSSQL.2\MSSQL\Data\Saw_Data.MDF'
-- The database log name
DECLARE @DatabASeLog VARCHAR(20)
SELECT @DatabASeLog = 'Saw_Live_Log'
-- The DatabAse Log Filename\location on the physical server (suffixed with LDF extension, EG. Saw_Log.LDF)
DECLARE @DatabASeLogLocation VARCHAR(250)
SELECT @DatabASeLogLocation = 'E:\Microsoft SQL Server\MSSQL.2\MSSQL\Data\Saw_Live_Log.LDF'
-- The DatabASe Login
DECLARE @DatabASeLogin VARCHAR(20)
SELECT @DatabASeLogin = 'sawadmin'
-- The DatabASe Login PASsword
DECLARE @DatabASePASsword VARCHAR(20)
SELECT @DatabASePASsword = 'systcent'
-------------------------------------------------------
-- DROP THE EXISTING DATABASE
-------------------------------------------------------
IF EXISTS (SELECT name FROM mASter.dbo.sysdatabASes WHERE name = @DataBaseName)
DROP DATABASE [@DataBaseName]
GO
-------------------------------------------------------
-- CREATE DATABASE
-------------------------------------------------------
CREATE DATABASE [@DataBaseName] ON
(NAME = @DatabASeFilename,
FILENAME = @DatabASeFileLocation ,
SIZE = 110,
FILEGROWTH = 10%)
LOG ON
(NAME = @DatabASeLog,
FILENAME = @DatabASeLogLocation,
SIZE = 1,
FILEGROWTH = 10%)
COLLATE Latin1_General_CI_AS
GO
Mark Davies
Warwickshire County Council