我正在使用sql bulk copy将数据从Table1复制到Table2表。我已经在Table2上应用了触发器,但我的触发器并不是在每一行都触发。这是我的触发器和sqlbulkcopy函数。
SqlConnection dstConn = new SqlConnection(ConfigurationManager.ConnectionStrings["Destination"].ConnectionString);
string destination = dstConn.ConnectionString;
//Get data from Source in our case T1
DataTable dataTable = new Utility().GetTableData("Select * From [db_sfp_ems].[dbo].[tbl_current_data_new] where [start_date]>'" + calculate_daily_Time + "' and status=0" , source);
SqlBulkCopy bulkCopy = new SqlBulkCopy(source, SqlBulkCopyOptions.FireTriggers)
{
//Add table name of source
DestinationTableName = "tbl_current_data",
BatchSize = 100000,
BulkCopyTimeout = 360
};
bulkCopy.WriteToServer(dataTable);
//MessageBox.Show("Data Transfer Succesfull.");
dstConn.Close();
-触发
ALTER TRIGGER [dbo].[trgAfterInsert] ON [dbo].[tbl_current_data]
AFTER INSERT
AS
BEGIN
declare @intime datetime
declare @sdp_id numeric
declare @value numeric(9,2)
SELECT @intime= DATEADD(SECOND, -DATEPART(SECOND, start_date), start_date) FROM INSERTED
SELECT @sdp_id= sdp_id FROM INSERTED
SELECT @value= value FROM INSERTED
INSERT INTO Table3(sdp_id,value,start_date)
VALUES
(
@sdp_id,@value,@intime
)
https://stackoverflow.com/questions/50617686
复制相似问题