如何重命名具有“.csv”在名称中的表格

huangapple go评论51阅读模式
英文:

How to rename a table that has ".csv" in the name

问题

我有一些表的名称以.csv结尾。即schema.table1.csv,schema.table2.csv。

如何去除.csv或重命名它们而不包含有问题的字符?

根据这个Stack Overflow问题,我尝试了这个:

exec sp_rename @objname = 'schema.[table1.csv]', @newname = 'table1';

但当我运行它时,我收到了以下错误消息:

为存储过程或函数sp_rename提供的参数不足。

根据@AlwaysLearning的问题,这是SELECT @@VERSION的结果:

Microsoft Azure SQL Data Warehouse - 10.0.20438.0 Jan 10 2023 20:57:20 Copyright (c) Microsoft Corporation

英文:

I have several tables whose names end with .csv. I.e. schema.table1.csv, schema.table2.csv.

How can I remove the .csv or rename them without the offending characters?

Per this SO question I tried this:

exec sp_rename @objname = 'schema.[table1.csv]', @newname = 'table1';

But I'm getting this error when I run it:

> An insufficient number of arguments were supplied for the procedure or function sp_rename.

Per @AlwaysLearning's question, here's the result of SELECT @@VERSION:
>Microsoft Azure SQL Data Warehouse - 10.0.20438.0 Jan 10 2023 20:57:20 Copyright (c) Microsoft Corporation

答案1

得分: 2

你可以使用以下命令:

RENAME OBJECT schema.[table1.csv] TO [table1];

详细信息请参考:https://learn.microsoft.com/en-us/sql/t-sql/statements/rename-transact-sql?view=azure-sqldw-latest

(顺便说一句,在Azure Synapse中,sp_rename是完全不同的东西。截止到今天,它仅支持对列的重命名。详细信息请参考这里:https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-rename-transact-sql?view=azure-sqldw-latest)

英文:

you can use:

RENAME OBJECT schema.[table1.csv] TO [table1];

for details see: https://learn.microsoft.com/en-us/sql/t-sql/statements/rename-transact-sql?view=azure-sqldw-latest

(Btw: sp_rename is totally something different in Azure Synapse. As of today It only supports renaming of a column only. See details here: https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-rename-transact-sql?view=azure-sqldw-latest)

huangapple
  • 本文由 发表于 2023年3月15日 21:03:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745111.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定