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\'
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.