简体   繁体   中英

SQL Server : drop schema with special characters

I've got an old schema that needs to be removed. Problem is it's got the special character \\ in the name (believe me I'm no fan of special characters in schema names). I have tried commands like the following

DROP SCHEMA databasename."COMPANY\user1"

where COMPANY\\user1 is the name of the schema.

However, I end up getting errors like the following

SQL Error: Incorrect syntax near '.'.`

I've dropped all of the tables inside of the schema, so I don't think there should be any objects remaining. I had success dropping tables with the following command

DROP TABLE databasename."COMPANY\user1".persontable;

Any idea why my attempt to drop the schema is failing? I'm sure it's something obvious I'm missing in the syntax.

Have you tried using square braces?

drop schema databasename.[COMPANY\user1]

Actually, this doesn't work, because drop schema doesn't accept the database (as sort of implied by the syntax in the documentation ). Just go into the database and do:

drop schema [COMPANY\user1]

This works for me with names that have unusual characters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM