短信 'Invalid column name'

SMSS 'Invalid column name'

在你斥责我'this has been asked here:'之前,我想指出我确实做到了google。在某些情况下,我什至去了第 3 页。 不寒而栗

所以这是交易: 我正在尝试审核我们拥有的数据库,为多个 table 设置 UPDATEINSERTDELETE 语句的触发器。已成功创建并链接触发器。每个触发器执行一个存储过程,将所需数据插入我们的 tick_audit table.

此信息是:

table还有一个PRIMARY_KEY、AUTO_INCREMENTid字段。

当我尝试创建存储过程时

create procedure update_tick_user
@UserId         varchar(32),
@ClientId       varchar(32),
@Table          varchar(64),
@TableRecord    varchar(512),
@Descr          varchar(128),
@RemoteIP       varchar(16)
as
begin
    insert into tick_audit ('user_account', 'client_id', 'date_time', 'table_name', 'table_record_id', 'descr', 'remote_ip_address')
    values
    (@UserId, @ClientId, getdate(), @Table, @TableRecord, @Descr, @RemoteIP)
end;

我收到以下错误:

Msg 207, Level 16, State 1, Procedure update_tick_user, Line 10 Invalid column name 'user_account'.

对每一列重复此操作。当我运行

exec sp_columns tick_audit

我从 tick_audit 中获取了所有列,甚至将它们的名称复制到列字段中进行插入,我也遇到了上述错误。当我只是 运行

时,我什至会遇到错误
insert into tick_audit 
('user_account', 'client_id', 'date_time', 'table_name', 'table_record_id', 'descr', 'remote_ip_address')
values
('', '', getdate(), '', '', '', '')

每当我尝试在不同的 table 上插入、更新或删除时,我都没有收到任何错误。如果我的 table 或某些超级秘密的骗局、仪式式的方法有问题,我有什么办法可以查明吗?

这是我到目前为止尝试过的方法:

祈祷,希望有人能帮助我。

不要在列名周围使用单引号。

create procedure update_tick_user
@UserId         varchar(32),
@ClientId       varchar(32),
@Table          varchar(64),
@TableRecord    varchar(512),
@Descr          varchar(128),
@RemoteIP       varchar(16)
as
begin
    insert into tick_audit (user_account, client_id, date_time, table_name, table_record_id, descr, remote_ip_address)
    values
    (@UserId, @ClientId, getdate(), @Table, @TableRecord, @Descr, @RemoteIP)
end;

删除'使insert如下

 insert into tick_audit (user_account, client_id, date_time, table_name, table_record_id, descr, remote_ip_address)
 values (@UserId, @ClientId, getdate(), @Table, @TableRecord, @Descr, @RemoteIP)

使用方括号代替引号:

insert into tick_audit ([user_account], [client_id], [date_time], [table_name], [table_record_id], [descr], [remote_ip_address])
values (@UserId, @ClientId, getdate(), @Table, @TableRecord, @Descr, @RemoteIP)

单引号用于文字。要分隔对象名称,您应该使用方括号或双引号,但只有当 QUOTED_IDENTIFIER 设置为 ON.

时才可以使用双引号