CREATE DATABASE using file in default path

前端 未结 6 1514
借酒劲吻你
借酒劲吻你 2021-02-05 03:28

I want to create an SQL script that creates a database. Right now, I have this:

CREATE DATABASE [Documents] ON  PRIMARY 
( NAME = N\'Documents\', FILENAME = N\'         


        
6条回答
  •  孤城傲影
    2021-02-05 04:22

    See How do I find the data directory for a SQL Server instance?

    If you are using SQL Server 2012 or higher, you can find the default path using

    select 
      InstanceDefaultDataPath = serverproperty('InstanceDefaultDataPath'),
      InstanceDefaultLogPath = serverproperty('InstanceDefaultLogPath')
    

    You can then use exec() to construct your CREATE DATABASE statement.

    This is useful if you want the physical file names of your database to be different from the default name.

提交回复
热议问题