title: Create Northwind.mdf for use in local db
body: <p>The following is the start if the standard Install Northwind sql script as provided by Microsoft in their Install sql server 200 sample databases.</p>
  
  <pre><code>SET NOCOUNT ON
  GO
  
  USE master
  GO
  if exists (select * from sysdatabases where name='Northwind')
          drop database Northwind
  go
  
  DECLARE @device_directory NVARCHAR(520)
  SELECT @device_directory = SUBSTRING(filename, 1, CHARINDEX(N'master.mdf', LOWER(filename)) - 1)
  FROM master.dbo.sysaltfiles WHERE dbid = 1 AND fileid = 1
  
  EXECUTE (N'CREATE DATABASE Northwind
    ON PRIMARY (NAME = N''Northwind'', FILENAME = N''' + @device_directory + N'northwnd.mdf'')
    LOG ON (NAME = N''Northwind_log'',  FILENAME = N''' + @device_directory + N'northwnd.ldf'')')
  go
  
  exec sp_dboption 'Northwind','trunc. log on chkpt.','true'
  exec sp_dboption 'Northwind','select into/bulkcopy','true'
  GO
  
  set quoted_identifier on
  GO
  </code></pre>
  
  <p>Under normal circumstances I always use a full copy of sql server or sql server express for development, however an unrelated support issue with a third party component has occurred that requires me to provide a self contained sample application with the basic nortwind database file contained within the sample using localdb.</p>
  
  <p>To that end how should I adapt the Execute Create Database section of the sql script so that it will create a copy of the nortwind .mdf in a given location (let's say C:\MyData  so that I can then use, that file to send with the sample I need to build for the support team.  Essentially it is vital that they have a completely self contained sample to help narrow down the problem.</p>
  
  <p>Many Thanks</p>