using System; using System.Data; using System.Data.SqlClient; using Microsoft.SqlServer.Server; public partial class Triggers { // 为目标输入现有表或视图并取消对属性行的注释 [Microsoft.SqlServer.Server.SqlTrigger (Name="Trigger1", Target="Unit_E", Event="FOR INSERT")] public static void Trigger1() { SqlPipe sp = SqlContext.Pipe; string sql = "insert into Unit_E1 select * from inserted"; using (SqlConnection conn = new SqlConnection("context connection=true")) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.Connection = conn; cmd.CommandText = sql; SqlDataReader rdr = cmd.ExecuteReader(); sp.Send(rdr); conn.Close(); } //SqlContext.Pipe.Send("Trigger FIRED"); } }
时间: 2024-10-12 18:14:26