使用脚本在默认路径下创建数据库?[英] Create database using script at the default path?

本文是小编为大家收集整理的关于使用脚本在默认路径下创建数据库?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我已经在SQL Server 2008中生成了数据库的脚本.生成的脚本具有硬编码路径,即创建数据库的位置.我不希望此路径被硬编码,我希望此路径使用脚本正在运行的数据库引擎的默认值.

这是脚本的一小部分:

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

路径C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\POS.mdf在所有计算机上可能都不存在,这就是为什么我希望数据库引擎选择它的原因

推荐答案

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

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

其他推荐答案

为什么不使用:

CREATE DATABASE [POS];

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

本文地址:https://www.itbaoku.cn/post/597534.html

问题描述

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 want this path to be hardcoded, I want this path to use the default of the database engine the script is running on.

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 the database engine

推荐答案

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

其他推荐答案

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.