Multipart identifier "insert.Id" cannot be linked when creating a trigger
I am trying to create a trigger on a table in SQL Server 2012 but it gives an error as shown below
"The multipart identifier" insert.Id "cannot be linked",
Executable request
CREATE TRIGGER dbo.[TR_t_documents_InsertUpdateDelete] ON
dbo.[t_documents] AFTER INSERT, UPDATE, DELETE
AS
BEGIN
UPDATE dbo.[t_documents]
SET dbo.[t_documents].[UpdatedAt] = CONVERT(DATETIMEOFFSET, SYSUTCDATETIME())
FROM
INSERTED
WHERE inserted.[Id] = dbo.[t_documents].[Id]
END
The same works successfully in SQL Server 2014.
Can anyone help me why this is happening on SQL Server 2012?
+3
source to share
1 answer
This is due to what you have for the database. In this case, you are using case sensitive collation, so the table names must be sequential. For virtual trigger tables, they must be in uppercase, for example:
CREATE TRIGGER dbo.[TR_t_documents_InsertUpdateDelete] ON
dbo.[t_documents] AFTER INSERT, UPDATE, DELETE
AS
BEGIN
UPDATE dbo.[t_documents]
SET dbo.[t_documents].[UpdatedAt] = CONVERT(DATETIMEOFFSET, SYSUTCDATETIME())
FROM
INSERTED
WHERE INSERTED.[Id] = dbo.[t_documents].[Id]
-- ^^^^^^^^
-- THIS!
END
+5
source to share