Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8913565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:29:39+00:00 2026-06-15T04:29:39+00:00

In my table there are three or more columns stored image file path, so

  • 0

In my table there are three or more columns stored image file path, so I need to store the image file path to an specify table ‘OnDeleteFile’ when the data is going to delete,then the program to delete file in web server in task methord from this specify table
but there are many tables like this satuation, i don’t want to write every times in every triggers to insert each column into table OnDeleteFile like this:

insert into OnDeleteFile(filePath) select column1 from deleted,
insert into OnDeleteFile(filePath) select column2 from deleted,
insert into OnDeleteFile(filePath) select column3 from deleted

there are so many tables and so many columns,so i hope i can do this by loop

tsql like this:

declare mycursor cursor fast_forward
for select columnName from #temptable where isContent=0 
open mycursor
fetch next from mycursor into @column 
while @@fetch_status = 0
begin
    select @sqlstr='insert into OnDeleteFile(fileType,filePath) select fileType=''image'',@columnName from deleted where @columnName is not null and @columnName <> '''' '
    exec sp_executesql
    @stat=@sqlstr,
    @params=N'@columnName as varchar(255)',
    @columnName=@column
    fetch next from mycurosr into @column 
end

And it run error :object name ‘deleted’ is invalid

I try this way :

declare mycursor cursor fast_forward
for select columnName from #temptable where isContent=0 
open mycursor
fetch next from mycursor into @column 
while @@fetch_status = 0
begin
    exec('insert into OnDeleteFile(fileType,filePath) select fileType=''image'','+ @column +' from deleted where '+ @column + ' is not null and '+ @column + ' <> '''' ')
end

fail again

I think the problem is the scope of deleted table can be used ,the deleted table can’t be access in proc sp_executesql

so only i can do is to create a temp table to walk around this problem , but if so ,for this simple goal ,i used trigger, cursor , temptable and sub procedure call , i really care about the cost of compute

if anyone have some better solutions?

PS: I’m very sorry for my pool English and my pool question

PPS:i know there are something wrong about the needs to do this complex thing ,if the programmer in our team be willing to delete file at the same time when delete the data ,i will no need to do this , but they won’t , so i just try in my scale

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:29:42+00:00Added an answer on June 15, 2026 at 4:29 am

    No, don’t do that, do it the way you don’t want to do.

    insert into OnDeleteFile(filePath) select column1 from deleted,
    insert into OnDeleteFile(filePath) select column2 from deleted,
    insert into OnDeleteFile(filePath) select column3 from deleted
    

    It’s a MUCH better idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am updating a table with spatial types and there are three or more
I need an advice on optimal approach to store statistical data. There is a
There is a table with more than 100,000 records matching a particular criteria of
I have users table. There are three other tables: developers, managers, testers. All of
I have a simple three table reference. It looks plain enough. The associations there
In a MySQL (5.1) database table there is data that represents: how long a
I use the following columns stored in a SQL table called tb_player: Date of
I have table with pageId, parentPageId, title columns. Is there a way to return
I need to store a list of columns/datatype pairs as app settings. The amount
I have a table that contains three user ID columns and an Active column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.