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

  • Home
  • SEARCH
  • 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
Is it possible via any Unix utility to read chunks of a remote file
is it possible to extend vim functionality via custom extension (preferably, written in Python)?
Is it possible to call into COM objects via x86 assembly language? If so,
Is it possible to programmatically either via the win32API (python) or via a command
Is it possible to override default value of WebClientProtocol.Timeout property via web.config? <httpRuntime executionTimeout=500
Is it possible to modify a registry value (whether string or DWORD) via a
Is it possible to replace the standard broken image via CSS or using another
Is it possible to get notified (without polling, but via an event) when a
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should

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.