Tuesday, February 14, 2012

CREATE DATABASE

There is a SQL script for creating a database.
CREATE DATABASE [testdb]
ON (NAME = N''testdb_Data'', FILENAME = N''e:\MSSQL7\data\testdb_Data.MDF'' , SIZE = 1, FILEGROWTH = 10%)
'LOG ON (NAME = N''testdb_Log'', FILENAME = N''testdb_Log.LDF'' , SIZE = 1, FILEGROWTH = 10%)
It is intended to run at a client machine and there is usually
no knowladge about SQL server location on server machine.
Is there any way to not use absolute paths in the script ?
Or is there any way to recognize on client machine (by using SQL)
the root path e:\MSSQL7\ where the instance of the SQL server was installed
?You might take a look at the script that installs the Northwind sample
database for 1 idea. It uses the following:
DECLARE @.device_directory NVARCHAR(520)
SELECT @.device_directory = SUBSTRING(phyname, 1,
CHARINDEX(N'master.mdf', LOWER(phyname)) - 1)
FROM master.dbo.sysdevices
WHERE (name = N'master')
EXECUTE (N'CREATE DATABASE Northwind
ON PRIMARY (NAME = N''Northwind'', FILENAME = N''' +
@.device_directory + N'northwnd.mdf'')
LOG ON (NAME = N''Northwind_log'', FILENAME = N''' +
@.device_directory + N'northwnd.ldf'')')
go
You can find the Northwind install script in this folder :
<drive_letter>:\Program Files\Microsoft SQL
Server\MSSQL\Install\instnwnd.sql
Gail Erickson [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights
"Vlad Gonchar" <VladG@.Frogware.com> wrote in message
news:%23U8ccg6eDHA.3076@.tk2msftngp13.phx.gbl...
> There is a SQL script for creating a database.
> CREATE DATABASE [testdb]
> ON (NAME = N''testdb_Data'', FILENAME => N''e:\MSSQL7\data\testdb_Data.MDF'' , SIZE = 1, FILEGROWTH = 10%)
> 'LOG ON (NAME = N''testdb_Log'', FILENAME = N''testdb_Log.LDF'' , SIZE => 1, FILEGROWTH = 10%)
> It is intended to run at a client machine and there is usually
> no knowladge about SQL server location on server machine.
> Is there any way to not use absolute paths in the script ?
> Or is there any way to recognize on client machine (by using SQL)
> the root path e:\MSSQL7\ where the instance of the SQL server was
installed
> ?
>|||Sorry to disappoint you Vlad, but physical file names and locations are
mandatory parameters, not only for SQL Server but for any other database
system.
"Vlad Gonchar" <VladG@.Frogware.com> wrote in message
news:#U8ccg6eDHA.3076@.tk2msftngp13.phx.gbl...
> There is a SQL script for creating a database.
> CREATE DATABASE [testdb]
> ON (NAME = N''testdb_Data'', FILENAME => N''e:\MSSQL7\data\testdb_Data.MDF'' , SIZE = 1, FILEGROWTH = 10%)
> 'LOG ON (NAME = N''testdb_Log'', FILENAME = N''testdb_Log.LDF'' , SIZE => 1, FILEGROWTH = 10%)
> It is intended to run at a client machine and there is usually
> no knowladge about SQL server location on server machine.
> Is there any way to not use absolute paths in the script ?
> Or is there any way to recognize on client machine (by using SQL)
> the root path e:\MSSQL7\ where the instance of the SQL server was
installed
> ?
>

No comments:

Post a Comment