简体   繁体   English

每个表中的列名必须唯一。 表'CONSUMO.DBO.ARCHIVOBOL082017'中的列名'MntNeto'被多次指定

[英]Column names in each table must be unique. Column name 'MntNeto' in table 'CONSUMO.DBO.ARCHIVOBOL082017' is specified more than once

I need to create column: 'MntNeto' with a default value of '0', 'Not Null' only if it does not exist in the table CONSUMO.DBO.ARCHIVOBOL082017 我需要创建列:'MntNeto',其默认值为'0','Not Null'仅当表CONSUMO.DBO.ARCHIVOBOL082017中不存在时

In Sql Server Query Analizer this string works fine, every time: 每次在Sql Server查询分析器中,此字符串都可以正常工作:

if not exists (select * from syscolumns where id=object_id('CONSUMO.DBO.ARCHIVOBOL082017') and name='MntNeto') alter table CONSUMO.DBO.ARCHIVOBOL082017 add MntNeto money default 0 not null

request.cookies("usa_bd") value is the name of the table, in this case: CONSUMO.DBO.ARCHIVOBOL082017 request.cookies(“ usa_bd”)值是表的名称,在这种情况下为:CONSUMO.DBO.ARCHIVOBOL082017

<%
set conn=server.createobject("adodb.connection")
 '********************************************
 'CONNECTION STRING **************************
%>
<!--#include file="xxxxx.asp"-->
<%
 '********************************************
 '********************************************
conn.open vamos

sqlstring = " if not exists (select * from syscolumns " &_
            " where id=object_id('" & trim(ucase(request.cookies("usa_bd"))) & "') and name='MntNeto') " &_
            " alter table " & trim(ucase(request.cookies("usa_bd"))) & " add MntNeto money default 0 not null"
            response.write sqlstring & "<br><br>"
Set RS = Conn.Execute(sqlstring)

conn.close
set conn = nothing
%>

From asp it will create the column only if it does not exist. 仅当不存在时,才从asp创建列。 If it does i got this error: 如果确实出现此错误:

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

From Sql Query analyzer it works everytime with no problems, though. 但是,从Sql Query分析器中,它每次都能正常运行。

The only way I know this could be happening is if your connection in your dot net app is NOT pointing to the CONSUMO database as its initial catalog. 我知道这可能发生的唯一方法是,如果您的点网应用程序中的连接未指向CONSUMO数据库作为其初始目录。 Therefore it's consulting the syscolumns table in the wrong database. 因此,它正在查询错误数据库中的syscolumns表。

You will get the same error in SSMS if you change the connection of your query window to a different database. 如果将查询窗口的连接更改为其他数据库,则会在SSMS中收到相同的错误。 At least, I do. 至少我知道。

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

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