在默认路径下使用脚本创建数据库?

时间:2022-06-20 02:54:44

I've generated a script of a database in SQL Server 2008. The generated script has the hardcoded path of where the database would be created. I don't this path to be hardcoded, I want this path to default of the database engine the script is running on or some like that.

我在SQL Server 2008中生成了一个数据库脚本。生成的脚本具有创建数据库的硬编码路径。我不需要硬编码这个路径,我希望这个路径是脚本运行的数据库引擎的默认路径。

Here is the small portion of the script:

下面是剧本的一小部分:

CREATE DATABASE [POS] ON  PRIMARY 
( NAME = N'POS', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\POS.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'POS_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\POS_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

The path C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\POS.mdf might not exist on all computers that's why I want it to be chosen by database engine

路径C:\Program Files\Microsoft SQL Server \ MSSQL10_50.SQLEXPRESS \该软件\ \ POS数据。mdf可能不存在于所有计算机上,所以我希望它由数据库引擎选择。

2 个解决方案

#1


33  

Simply create the database and then adjust all the needed properties directly in files

只需创建数据库,然后直接在文件中调整所有需要的属性。

CREATE DATABASE [POS] 
GO
ALTER DATABASE POS MODIFY FILE 
( NAME = N'POS' , SIZE = 3048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
GO
ALTER DATABASE POS MODIFY FILE 
( NAME = N'POS_log' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

#2


16  

Why don't use just:

为什么不使用:

CREATE DATABASE [POS];

This will create the database with all the default settings (including paths). You may alter any setting you like later on.

这将创建具有所有默认设置(包括路径)的数据库。稍后您可以更改任何您喜欢的设置。

#1


33  

Simply create the database and then adjust all the needed properties directly in files

只需创建数据库,然后直接在文件中调整所有需要的属性。

CREATE DATABASE [POS] 
GO
ALTER DATABASE POS MODIFY FILE 
( NAME = N'POS' , SIZE = 3048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
GO
ALTER DATABASE POS MODIFY FILE 
( NAME = N'POS_log' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

#2


16  

Why don't use just:

为什么不使用:

CREATE DATABASE [POS];

This will create the database with all the default settings (including paths). You may alter any setting you like later on.

这将创建具有所有默认设置(包括路径)的数据库。稍后您可以更改任何您喜欢的设置。