title: How can I create a new database with schema within a stored procedure?
body: <p>I want to write a TSQL stored procedure that creates a database with a specified name, and pre-populates it with some schema.</p>
  
  <p>So I use lots of EXEC statements:</p>
  
  <pre><code>EXEC('CREATE TABLE ' + @dbName + '.dbo.MyTable (...)');
  </code></pre>
  
  <p>etc, along with some <code>CREATE PROCEDURE</code>, <code>CREATE FUNCTION</code> etc. However, the problem comes from when I want to create a type, as CREATE TYPE statements can't have the database specified, and you can't have <code>USE @dbName</code> within the stored procedure.</p>
  
  <p>How can I create a type in another database in a stored procedure?</p>