Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 插入SQL Server 2008后的触发器_Sql Server 2008_Triggers - Fatal编程技术网

Sql server 2008 插入SQL Server 2008后的触发器

Sql server 2008 插入SQL Server 2008后的触发器,sql-server-2008,triggers,Sql Server 2008,Triggers,触发器在MSSM和前端应用程序中成功执行。当执行insert查询时,应用程序将挂起并停止响应。但当我输入一个硬编码值而不是最后插入的值时,它工作得非常好。我不确定我最后插入的语法是错误的还是我在其他地方出错了 这里我试图从一个数据库表中获取最后一个插入的唯一id,并将其插入另一个具有当前时间戳的数据库表中 这方面的帮助真的很感激 USE [Dummy_Ibus] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER TRIGGER [

触发器在MSSM和前端应用程序中成功执行。当执行insert查询时,应用程序将挂起并停止响应。但当我输入一个硬编码值而不是最后插入的值时,它工作得非常好。我不确定我最后插入的语法是错误的还是我在其他地方出错了

这里我试图从一个数据库表中获取最后一个插入的唯一id,并将其插入另一个具有当前时间戳的数据库表中

这方面的帮助真的很感激

USE [Dummy_Ibus]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[insert_veh_bus] ON [dbo].[tcbus]
AFTER INSERT
AS

BEGIN
SET NOCOUNT ON;
DECLARE @last_inserted_unique_id NUMERIC(10,0);

SET @last_inserted_unique_id = 0;

select @last_inserted_unique_id = inserted.unique_id from inserted;

INSERT INTO bbus_sync.dbo.sync_history(unique_id,created_on) VALUES(@last_inserted_unique_id,CURRENT_TIMESTAMP)

END

确保bbus_同步数据库不会出现权限问题?第二,不要在触发器中使用标量变量,请参见.1。权限存在,用户具有DBO级别的权限。2.我甚至尝试将此插入到bbus_sync.dbo.sync_history unique_id中,在值上创建了选择inserted.unique_id from inserted,当前\u时间戳为什么使用值,使用直接插入bbus\u sync.dbo.sync\u History unique\u id,在选择唯一\u id时创建\u,插入的当前\u时间戳确保bbus\u sync数据库不会出现权限问题?第二,不要在触发器中使用标量变量,请参见.1。权限存在,用户具有DBO级别的权限。2.我甚至尝试将此插入到bbus_sync.dbo.sync_history unique_id中,在值上创建了选择inserted.unique_id from inserted,当前\u时间戳为什么使用值,使用直接插入bbus\u sync.dbo.sync\u History unique\u id,在选择唯一\u id时创建\u,插入的当前\u时间戳确保bbus\u sync数据库不会出现权限问题?第二,不要在触发器中使用标量变量,请参见.1。权限存在,用户具有DBO级别的权限。2.我甚至尝试将此插入到bbus_sync.dbo.sync_history unique_id中,在值上创建了选择inserted.unique_id from inserted,当前\u时间戳为什么使用值,使用直接插入bbus\u sync.dbo.sync\u历史唯一\u id,在选择唯一\u id时创建\u,从插入的当前\u时间戳