SQL Server:无法更新表中的列

时间:2021-10-15 03:26:40

I cannot work out why my column is not being updated.

我无法弄清楚为什么我的专栏没有更新。

I have added a new column to an existing table as follows:

我在现有表中添加了一个新列,如下所示:

ALTER TABLE dbname..tablename 
  ADD RejectedCode [varchar](5) NULL

When I run the query below:

当我运行以下查询时:

UPDATE dbname..tablename 
SET RejectedCode = 'OTHER',
    Notes = 'DEBUG'
WHERE RecordID = 12345

it says:

(1 row(s) affected)

I check the respective record and I can see the Notes column updated, but the new column still displays NULL and I don't get any error message.

我检查相应的记录,我可以看到Notes列更新,但新列仍然显示NULL,我没有收到任何错误消息。

What am I doing wrong? Many thanks for help.

我究竟做错了什么?非常感谢你的帮助。

3 个解决方案

#1


3  

Looks like you have trigger instead of update on your table

看起来你有触发而不是更新你的桌子

#2


1  

Instead of updating directly try dynamic query like below,

而不是直接更新尝试动态查询,如下所示,

 EXEC('Update dbname..tablename    SET RejectedCode = ''OTHER'',
        Notes = ''DEBUG'' WHERE RecordID = 12345') 

#3


1  

Seem like there is a INSTEAD OF UPDATE trigger on your table. to find out triggers associated with the table do as below.

好像桌子上有一个INSTEAD OF UPDATE触发器。找出与表相关的触发器,如下所示。

In object explorer go to your table-name and click on triggers node.

在对象资源管理器中,转到您的表名并单击触发器节点。

or use the below code

或使用以下代码

SELECT 
     sysobjects.name AS trigger_name 
    ,USER_NAME(sysobjects.uid) AS trigger_owner 
    ,s.name AS table_schema 
    ,OBJECT_NAME(parent_obj) AS table_name 
    ,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS isupdate 
    ,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS isdelete 
    ,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS isinsert 
    ,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS isafter 
    ,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS isinsteadof 
    ,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS [disabled] 
FROM sysobjects 

INNER JOIN sysusers 
    ON sysobjects.uid = sysusers.uid 

INNER JOIN sys.tables t 
    ON sysobjects.parent_obj = t.object_id 

INNER JOIN sys.schemas s 
    ON t.schema_id = s.schema_id 

WHERE sysobjects.type = 'TR' 
and s.name = 'your table name'

#1


3  

Looks like you have trigger instead of update on your table

看起来你有触发而不是更新你的桌子

#2


1  

Instead of updating directly try dynamic query like below,

而不是直接更新尝试动态查询,如下所示,

 EXEC('Update dbname..tablename    SET RejectedCode = ''OTHER'',
        Notes = ''DEBUG'' WHERE RecordID = 12345') 

#3


1  

Seem like there is a INSTEAD OF UPDATE trigger on your table. to find out triggers associated with the table do as below.

好像桌子上有一个INSTEAD OF UPDATE触发器。找出与表相关的触发器,如下所示。

In object explorer go to your table-name and click on triggers node.

在对象资源管理器中,转到您的表名并单击触发器节点。

or use the below code

或使用以下代码

SELECT 
     sysobjects.name AS trigger_name 
    ,USER_NAME(sysobjects.uid) AS trigger_owner 
    ,s.name AS table_schema 
    ,OBJECT_NAME(parent_obj) AS table_name 
    ,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS isupdate 
    ,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS isdelete 
    ,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS isinsert 
    ,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS isafter 
    ,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS isinsteadof 
    ,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS [disabled] 
FROM sysobjects 

INNER JOIN sysusers 
    ON sysobjects.uid = sysusers.uid 

INNER JOIN sys.tables t 
    ON sysobjects.parent_obj = t.object_id 

INNER JOIN sys.schemas s 
    ON t.schema_id = s.schema_id 

WHERE sysobjects.type = 'TR' 
and s.name = 'your table name'