简体   繁体   English

错误:列“EP_TEXT”指定了多次

[英]ERROR: column “EP_TEXT” specified more than once

I try to use script to add column to table, no matter i change to which name, it always return error saying我尝试使用脚本将列添加到表中,无论我更改为哪个名称,它总是返回错误说

Column names in each table must be unique.每个表中的列名必须是唯一的。 Column name 'xxx' in table 'TEST_TABLE' is specified more than once.表“TEST_TABLE”中的列名“xxx”被指定了多次。

I randomly key in a name, it still saying that name is specified more than once.我随机输入一个名字,它仍然说这个名字被指定了不止一次。 but actually not, there is no such column existed yet, and column finally is not added successfully also.但实际上没有,还没有这样的列,并且列 finally 也没有添加成功。

anyone had any idea?有人知道吗? thanks谢谢

below is my query:以下是我的查询:

GO
if not exists(SELECT * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'TEST_TABLE' AND COLUMN_NAME = 'EP_TEXT')
begin 
ALTER TABLE TEST_TABLE ADD EP_TEXT [dbo].[UDDT_MAXVARCHAR] NULL
end 
GO

The problem is that INFORMATION_SCHEMA.TABLE does not have a COLUMN_NAME column.问题是 INFORMATION_SCHEMA.TABLE 没有 COLUMN_NAME 列。 Try this:尝试这个:

IF NOT EXISTS(
     SELECT * from INFORMATION_SCHEMA.TABLES t1
              INNER JOIN INFORMATION_SCHEMA.COLUMNS t2 on t1.TABLE_NAME = t2.TABLE_NAME
              where t1.TABLE_NAME = 'TEST_TABLE' and t2.COLUMN_NAME = 'EP_TEXT'
     )

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

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