title: Can i use sp_msforeachDB for registration procedure in all databese
body: <p>I must resister the same stored procedure in many - over 200 - databases.</p>
  <p>I tried this:</p>
  <pre><code>-------------------------------------------------------------
  DECLARE DB_CURSOR CURSOR FOR 
       SELECT name 
       FROM sys.databases 
  
  OPEN DB_CURSOR
  
  FETCH NEXT FROM DB_CURSOR INTO @DB_NAME
  
  WHILE @@FETCH_STATUS = 0
  BEGIN
      SET @sql1 = '---' ←Create Procedure
  
      SET @sql0 = 'USE [' + @DB_NAME + ']; EXEC(''' + @sql1 + ''')'
  
      EXEC(@sql0)
  END
  
  -------------------------------------------------------------
  </code></pre>
  <p>I checked escape sequence and my query are normal. However, this code valid in only first database.</p>
  <p>And it can repeat while number of database, but run at first database.</p>
  <p>Is it why?</p>
  <p>I searched many website, haven't prove yet.</p>
  <p>Please help me.</p>
  <p>If possible I want to solve it by a method that does not use sysobject.</p>
  <p>Thanks for your advice.</p>