当数据插入到另一个表中时触发使用时间戳更新表

时间:2018-11-28 03:55:13

标签: sql-server triggers

我对触发器非常陌生。在这里需要帮助。

我有两个表Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: devices/linux-rasp-pi3-g++ (arm, CPU features: neon) Configuration: cross_compile compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 concurrent dbus no-pkg-config reduce_exports stl Build options: Mode ................................... release Optimize release build for size ........ no Building shared libraries .............. yes Using C++ standard ..................... C++11 Using ccache ........................... no Using gold linker ...................... no Using new DTAGS ........................ yes Using precompiled headers .............. yes Using LTCG ............................. no Target compiler supports: NEON ................................. yes Build parts ............................ libs Qt modules and options: Qt Concurrent .......................... yes Qt D-Bus ............................... yes Qt D-Bus directly linked to libdbus .... no Qt Gui ................................. yes Qt Network ............................. yes Qt Sql ................................. yes Qt Testlib ............................. yes Qt Widgets ............................. yes Qt Xml ................................. yes Support enabled for: Using pkg-config ....................... no udev ................................... yes Using system zlib ...................... yes Qt Core: DoubleConversion ....................... yes Using system DoubleConversion ........ yes GLib ................................... no iconv .................................. yes ICU .................................... no Tracing backend ........................ <none> Logging backends: journald ............................. no syslog ............................... no slog2 ................................ no Using system PCRE2 ..................... no Qt Network: getifaddrs() ........................... yes IPv6 ifname ............................ yes libproxy ............................... no Linux AF_NETLINK ....................... yes OpenSSL ................................ yes Qt directly linked to OpenSSL ........ no OpenSSL 1.1 ............................ no SCTP ................................... no Use system proxies ..................... yes Qt Gui: Accessibility .......................... yes FreeType ............................... yes Using system FreeType ................ no HarfBuzz ............................... yes Using system HarfBuzz ................ no Fontconfig ............................. no Image formats: GIF .................................. yes ICO .................................. yes JPEG ................................. yes Using system libjpeg ............... yes PNG .................................. yes Using system libpng ................ yes EGL .................................... yes OpenVG ................................. no OpenGL: Desktop OpenGL ....................... no OpenGL ES 2.0 ........................ yes OpenGL ES 3.0 ........................ yes OpenGL ES 3.1 ........................ yes OpenGL ES 3.2 ........................ yes Vulkan ................................. no Session Management ..................... yes Features used by QPA backends: evdev .................................. yes libinput ............................... no INTEGRITY HID .......................... no mtdev .................................. no tslib .................................. yes xkbcommon-evdev ........................ no QPA backends: DirectFB ............................... no EGLFS .................................. yes EGLFS details: EGLFS OpenWFD ........................ no EGLFS i.Mx6 .......................... no EGLFS i.Mx6 Wayland .................. no EGLFS RCAR ........................... no EGLFS EGLDevice ...................... no EGLFS GBM ............................ no EGLFS VSP2 ........................... no EGLFS Mali ........................... no EGLFS Raspberry Pi ................... yes EGL on X11 ........................... no LinuxFB ................................ yes VNC .................................... yes Mir client ............................. no X11: Using system-provided XCB libraries .. yes EGL on X11 ........................... no Xinput2 .............................. yes XCB XKB .............................. yes XLib ................................. yes XCB render ........................... yes XCB GLX .............................. yes XCB Xlib ............................. yes Using system-provided xkbcommon ...... no Native painting (experimental) ....... no Qt Widgets: GTK+ ................................... no Styles ................................. Fusion Windows Qt PrintSupport: CUPS ................................... yes Qt Sql: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... yes PostgreSQL ............................. no SQLite2 ................................ yes SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... yes Qt Testlib: Tester for item models ................. yes Note: Also available for Linux: linux-clang linux-icc Note: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing. [dbo].[Demand_Request]

[dbo].[Modified_Demand_Request]

将数据插入CREATE TABLE [dbo].[Demand_Request] ( [CASE_ID] [INT] NULL, [TE_PART_NUMBER] [NVARCHAR](50) NULL, [VALUE] [FLOAT] NULL, [DEMAND_DATE] [DATETIME] NULL ) CREATE TABLE [dbo].[Modified_Demand_Request] ( [CASE_ID] [INT] NULL, [TE_PART_NUMBER] [NVARCHAR](50) NULL, [VALUE] [FLOAT] NULL, [DEMAND_DATE] [DATETIME] NULL, [Modified_On] [DATETIME] NULL ) 时,我想将相同的数据以及时间戳添加到表[dbo].[Demand_Request]中。

以下是我的触发器,但它不起作用:

[dbo].[Modified_Demand_Request]

2 个答案:

答案 0 :(得分:0)

尝试一下$("#ssr")

FOR INSERT

用于DEMO REXTESTER

其他参考:Firing Trigger for Bulk Insert

答案 1 :(得分:0)

我可以知道您如何插入数据。我尝试了与以下相同的操作(使用“ FOR INSERT”触发器),并且能够获取Modified_Demand_Request表中的数据。

    insert into [Demand_Request] values(1,'Test',1.0,GETDATE())
    insert into [Demand_Request] values(2,'Test1',1.0,GETDATE())
    insert into [Demand_Request] values(3,'Test2',1.0,GETDATE())
    insert into [Demand_Request] values(14,'Test2',1.0,GETDATE())