sql - 创建没有文件名的数据库?

标签 sql sql-server tsql

是否可以仅通过为其提供不带文件名的逻辑名称来创建数据库-> 这将导致在默认路径中使用数据库名称.mdf 创建数据库?

CREATE DATABASE A
ON PRIMARY (
name = Z)

我从 Microsoft 文档中找到了这个:

If data file name is not specified, SQL Server uses database_name as both the logical_file_name and as the os_file_name. The default path is obtained from the registry. The default path can be changed by using the Server Properties (Database Settings Page) in Management Studio. Changing the default path requires restarting SQL Server.



为什么当我尝试上面的查询时出现错误:

File option FILENAME is required in this CREATE/ALTER DATABASE statement.



除非我误解了什么data file name指这里。

最佳答案

这是 SQL Server CREATE DATABASE 的限制句法。根据documentation , <filespec>条款是可选的。但是,在指定时(以包括非默认逻辑名称),必须同时指定 NAME 和 FILENAME。 <filespec>子句语法是:

{  
(  
    NAME = logical_file_name ,  
    FILENAME = { 'os_file_name' | 'filestream_path' }   
    [ , SIZE = size [ KB | MB | GB | TB ] ]   
    [ , MAXSIZE = { max_size [ KB | MB | GB | TB ] | UNLIMITED } ]   
    [ , FILEGROWTH = growth_increment [ KB | MB | GB | TB | % ] ]  
)  
} 

关于sql - 创建没有文件名的数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43707050/

相关文章:

sql - 什么相当于 SQL 中的数组?

python - 如何删除表中除前 5 条记录之外的所有记录

mysql - 使用带有日期字符串的 LIKE 子句进行查询

c# - 在 C# 中使用 Enum 表示数据层对象的 'status'

sql - 插入期间表被锁定...网站无法使用(sql server 2008)

c# - 使用 C# 运行带有关键字 GO 的 .sql 语句?

mysql - SQL如何每次倒序选择一定数量的数据

asp.net - IIS 性能

sql - 如果不存在则创建 UDF(用户定义函数),如果存在则跳过它

sql-server - 查找所有正在使用链接服务器的 View