Dropping a table with a non-printable character in its name I have a legacy table with a name containing non-printable characters (CHAR(31), to be specific). 

The non-printable character is beside a underscore, and I've discovered that the shortcut CTRL+SHIFT+_ creates the CHAR(31) character (which means "US" - Unit Separator). The previous developer could have hit this combination by mistake, and created the table with this weird character in it. 

When we issue a SELECT command against the table, it returns results. But when we try to issue any DDL against it (DROP, sp_rename, etc), the character causes a problem.

Examples: 

DROP TABLE Table_Name;


Raises:


  Msg 15225 - No item by the name of 'Table_Name' could be found in the current database 'MyDB', given that @itemtype was input as '(null)'.


EXEC sp_rename N'Table_Name', N'NewTableName'; 


Raises:


  Msg 102 - Incorrect syntax near '_Name'. 


I already duplicated the table with the correct name, and have corrected it on the dependent objects. The remaining step is just dropping it from the database. 

Just an insight: when we copy+paste from SQL Server to Notepad++, it shows the hidden character ("US") on the middle of the table name, beside the underscore:
Since you already know which character is hidden, you can easily construct the current name using a variable, pass that into sp_rename, and then drop the table using the newly acquired name:

DECLARE @t nvarchar(128) = N'dbo.Table' + NCHAR(31) + N'_Name';
EXEC sys.sp_rename @t, N'NewTableName', N'OBJECT';
DROP TABLE dbo.NewTableName;


(Always be careful about using the proper schema identifier.)

Even easier would be to take your string that you know has the character in it, and wrap it in square brackets. This worked for me just fine:

DROP TABLE dbo.[Table_Name];
---------------------^
-- There is an NCHAR(31) right before the underscore


If you didn't know the trouble character(s), you could pull the name from the catalog view, identifying it by surrounding characters, then loop through the characters to determine which are problematic. Here's a full repro:

USE tempdb;
GO

DECLARE @sql NVARCHAR(MAX);
SET @sql = N'CREATE TABLE dbo.[Table' + NCHAR(31) + N'_Name](ID INT);';
EXEC sys.sp_executesql @sql;
GO

DECLARE @var NVARCHAR(128);
SELECT @var = name 
  FROM sys.tables 
  WHERE name LIKE N'Table%Name';

-- is it the right one?
PRINT @var;

DECLARE @i INT;
SET @i = 1;
WHILE @i &lt;= LEN(@var)
BEGIN
  PRINT SUBSTRING(@var, @i, 1) + N' =&gt; ' + RTRIM(UNICODE(SUBSTRING(@var, @i, 1)));
  SET @i = @i + 1;
END


Results:

Table_Name
T =&gt; 84
a =&gt; 97
b =&gt; 98
l =&gt; 108
e =&gt; 101
 =&gt; 31
_ =&gt; 95
N =&gt; 78
a =&gt; 97
m =&gt; 109
e =&gt; 101


And then don't forget to chide or smack the person responsible for a table getting into the system that way in the first place, if they're still employed in the industry.