删除SQL中包含点和方括号的列

删除SQL中包含点和方括号的列,sql,sql-server,rename,sql-delete,Sql,Sql Server,Rename,Sql Delete,如何删除SQL server中的列名[database].[dbo].[my_table].[col_name],即带有点和方括号的列名。换句话说,它是我想要的列名,但前缀是数据库名和shema。 我尝试了许多基于互联网的组合,例如,但没有成功。 谢谢。在带分隔符的标识符中,']'被转义为']],'['和'.'不需要转义 所以像这样: create table #tt(id int, [[database]].[dbo]].[my_table]].[col_name]]] int) alter

如何删除SQL server中的列名
[database].[dbo].[my_table].[col_name]
,即带有点和方括号的列名。换句话说,它是我想要的列名,但前缀是数据库名和shema。 我尝试了许多基于互联网的组合,例如,但没有成功。
谢谢。

在带分隔符的标识符中,']'被转义为']],'['和'.'不需要转义

所以像这样:

create table #tt(id int, [[database]].[dbo]].[my_table]].[col_name]]] int)

alter table #tt drop column [[database]].[dbo]].[my_table]].[col_name]]]

在分隔标识符中,“]”转义为“]]”,“[”和“.”不需要转义

所以像这样:

create table #tt(id int, [[database]].[dbo]].[my_table]].[col_name]]] int)

alter table #tt drop column [[database]].[dbo]].[my_table]].[col_name]]]

我不明白您是想重命名此列还是要删除它,但这里介绍了如何同时重命名和删除这两个列

CREATE TABLE JustTest(
  Col1 INT,
  [[database]].[dbo]].[my_table]].[col_name]]] INT
);

-- To rename the column use this
EXEC sp_rename 'JustTest.[[database]].[dbo]].[my_table]].[col_name]]]', 
               'NewName', 
               'COLUMN';

-- If the table is TempTable use this
EXEC tempdb.sys.sp_rename N'#TMP.[[database]].[dbo]].[my_table]].[col_name]]]',
                N'NewName',
                N'COLUMN';

-- To drop it use this
ALTER TABLE JustTest DROP COLUMN [[database]].[dbo]].[my_table]].[col_name]]];

我不明白您是想重命名此列还是要删除它,但这里介绍了如何同时重命名和删除这两个列

CREATE TABLE JustTest(
  Col1 INT,
  [[database]].[dbo]].[my_table]].[col_name]]] INT
);

-- To rename the column use this
EXEC sp_rename 'JustTest.[[database]].[dbo]].[my_table]].[col_name]]]', 
               'NewName', 
               'COLUMN';

-- If the table is TempTable use this
EXEC tempdb.sys.sp_rename N'#TMP.[[database]].[dbo]].[my_table]].[col_name]]]',
                N'NewName',
                N'COLUMN';

-- To drop it use this
ALTER TABLE JustTest DROP COLUMN [[database]].[dbo]].[my_table]].[col_name]]];
你想重命名列还是删除列?那里的链接让我有点困惑你想重命名列还是删除列?那里的链接让我有点困惑