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 129027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:43:43+00:00 2026-05-11T05:43:43+00:00

Is it possible via script/tool to generate a delete statement based on the tables

  • 0

Is it possible via script/tool to generate a delete statement based on the tables fk relations.

i.e. I have the table: DelMe(ID) and there are 30 tables with fk references to its ID that I need to delete first, is there some tool/script that I can run that will generate the 30 delete statements based on the FK relations for me ?

(btw I know about cascade delete on the relations, I can’t use it in this existing db)

I’m using Microsoft SQL Server 2008

  • 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. 2026-05-11T05:43:44+00:00Added an answer on May 11, 2026 at 5:43 am

    DELETE statements generated for use in SP with parameter, and as ON DELETE triggers: (this variant supports single column FKs only)

    SELECT 'DELETE '+detail.name+' WHERE '+dcolumn.name+' = @'+mcolumn.name AS stmt,      'DELETE ' + detail.name + ' FROM ' + detail.name + ' INNER JOIN deleted ON ' +      detail.name + '.' + dcolumn.name + ' = deleted.' + mcolumn.name AS trg FROM sys.columns AS mcolumn  INNER JOIN sys.foreign_key_columns ON mcolumn.object_id =              sys.foreign_key_columns.referenced_object_id      AND  mcolumn.column_id = sys.foreign_key_columns.referenced_column_id  INNER JOIN sys.tables AS master ON mcolumn.object_id = master.object_id  INNER JOIN sys.columns AS dcolumn      ON sys.foreign_key_columns.parent_object_id = dcolumn.object_id      AND sys.foreign_key_columns.parent_column_id = dcolumn.column_id  INNER JOIN sys.tables AS detail ON dcolumn.object_id = detail.object_id WHERE (master.name = N'MyTableName') 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible via script/tool to generate authomatically many delete statements based on the
I'm wondering if it's possible in OpenGL (via extensions or otherwise) to have an
Is it possible to transfer files via an ODATA service? when there is a
Possible Duplicate: Pass variables to ruby script via command line I am trying to
Is there a way to run the following script via PHP http://www.magentoadvisor.com/magento-backup/tutorial-magento-backup-scripts-part-2/ I have
Is it possible to change the Windows command prompt working directory via Python script?
I have to request data for a JS-script from a MySQL database (based upon
Is it possible to change an element value in CSS via sh script in
is possible via the Windows API's to enumerate and iterate the VCL controls on
Is it possible via an attribute of some sort to serialize a string as

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.