title: Rename SQL table test[']2
body: <p>Can anyone tell me how I rename this table?</p>
  
  <pre><code>test[']2
  </code></pre>
  
  <p>I have tried <code>EXEC sp_rename 'test['']2', 'abc'</code> in every combination.. and it fails with <code>Syntax error parsing SQL identifier</code></p>
  
  <p>I have tried the following </p>
  
  <pre><code>EXEC sp_rename 'test['']2', 'abc';
  EXEC sp_rename 'test[]'']2', 'abc';
  EXEC sp_rename '[test['']2]', 'abc';
  EXEC sp_rename '[test[]'']2]', 'abc';
  EXEC sp_rename [test[]']2], 'abc';
  EXEC sp_rename [test[']2], 'abc';
  </code></pre>
  
  <p>has anyone any other ideas?</p>
  
  <hr>
  
  <p>SOLUTION</p>
  
  <p>In case you come across this same problem and want to rename a table safely, here is a link to the code</p>
  
  <p>It is based on using the object_id of the table which you get from sys.tables, but you could easily change the code to use a table name</p>
  
  <p><a href="http://snipt.org/xoYm" rel="nofollow">Rename MSSQL Table</a></p>