title: Clone a SQL Server database programmatically
body: <p>I am attempting to write a SQL script that copies and renames a database. I've split it into two parts as features independently, so the restore is giving me a hard time. For example this is approximately what I have now. </p>
  
  <pre><code>BACKUP DATABASE [@dbName] 
  TO DISK = 'path' WITH COPY_ONLY;
  
  RESTORE DATABASE [@newDbName] 
  FROM DISK = 'path';
  </code></pre>
  
  <p>How can I alter this to automatically copy? </p>