Trigger would not be the best place to do such a thing.
Use a scheduled powershell or python script.
Why do you need to do this ?
What is the requirement?
use sqlteam
go
create table products(id int, name varchar(50))
create table products_logger(id int, isExported bit default(0) )
create trigger it_products on products
for insert
as
begin
insert into products_logger(id)
Select id from inserted
end
go
insert into products
select 1, 'rice' union
select 2, 'onion'
select 3, 'Meat'
Powershell part (schedule it to run every x Minute)
#Variables - details of the connection, stored procedure and parameters
$connectionString = "server=localhost;database='sqlteam';trusted_connection=true;";
#SQL Connection - connection to SQL server
$sqlConnection = new-object System.Data.SqlClient.SqlConnection;
$sqlConnection.ConnectionString = $connectionString;
#SQL Command - set up the SQL call
$sqlCommand = New-Object System.Data.SqlClient.SqlCommand;
$sqlCommand.Connection = $sqlConnection;
$sqlCommand.CommandText = 'select p.id, name From products_logger l join products p on l.id = p.id where isexported = 0';
#SQL Adapter - get the results using the SQL Command
$sqlAdapter = new-object System.Data.SqlClient.SqlDataAdapter
$sqlAdapter.SelectCommand = $sqlCommand
$dataSet = new-object System.Data.Dataset
$recordCount = $sqlAdapter.Fill($dataSet)
#Get single table from dataset
$data = $dataSet.Tables[0]
#Loop through each row of data and create a new file
foreach($row in $data)
{
$filename = "C:\_work\TeachYourself\PowerShell\" + $row.id
$row | export-csv "$filename.csv" -notypeinformation
#trip exported rows
$update = "update tgt set tgt.isexported = 1 from products_logger tgt where id = " + $row.id
Invoke-Sqlcmd -Query $update -ConnectionString $connectionString
Write-Output $update
}
#Close SQL Connection
$sqlConnection.Close();