简体   繁体   English

SQL Server:删除带有特殊字符的架构

[英]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. 其中COMPANY\\user1是架构的名称。

However, I end up getting errors like the following 但是,我最终收到如下错误

SQL Error: Incorrect syntax near '.'.` SQL错误:“。”附近的语法不正确。

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 ). 实际上,这是行不通的,因为drop schema不接受数据库(如文档中的语法所隐含的那样)。 Just go into the database and do: 只需进入数据库并执行:

drop schema [COMPANY\user1]

This works for me with names that have unusual characters. 这对我来说具有不寻常字符的名称有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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