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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:06:41+00:00 2026-06-13T00:06:41+00:00

I have a table which has id and statement columns, statement column contains statement

  • 0

I have a table which has id and statement columns, statement column contains statement like insert into tablename, update tablename, delete tablename (tablename might be any xxx), I have a scenario where I need to write a stored procedure, if I run SP it should get the insert records in statement column first with parent tablenames first and then child table insert into statement and after inserts update statement should come in any fashion and at last delete statement with child table statement first and then parent.

Output should be like

statements
INSERT INTO country(parent to state)
INSERT INTO state(parent to city)
INSERT INTO city(parent to zipcode)
INSERT INTO zipcode
  • 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-13T00:06:42+00:00Added an answer on June 13, 2026 at 12:06 am

    Hi to get your procedure done you must keep 1 more column like seqno int and update seqno with parent child levels . It will be very difficult to read table names from the statement column and find the parent child levels from sql server
    so i am assuming you are having seqno in that table then u can write proc as following

     DECLARE @table table (statements varchar(200),id int,seqno int)
    INSERT INTO @table 
    values('INSERT INTO country(parent to state)',1,1),
     ('INSERT INTO state(parent to city)',2,2),
     ('INSERT INTO city(parent to zipcode)' ,3,3),
     ('INSERT INTO zipcode' ,4,4),
     ('update  city(parent to zipcode)' ,4,3),
     ('delete FROM country' ,7,1),
     ('delete FROM zipcode' ,6,4)
    --- you can change below code to proc  u can write case statements if u want only inset or delete like that
    DECLARE @outtable table(statements varchar(200),seqno int,id int iDENTITY(1,1))
    INSERT INTO @outtable
    SELECT  statements,seqno FROM @table WHERE statements like '%insert%' ORDER BY seqno   ASC
    INSERT INTO @outtable
    SELECT  statements,seqno FROM @table WHERE statements like '%update%' ORDER BY seqno ASC
    INSERT INTO @outtable
    SELECT  statements,seqno FROM @table WHERE statements like '%delete%' ORDER BY seqno     DESC
    SELECT   * FROM @outtable order by id asc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which has a column called Direct of type char(1). It's
I have a table which has the below columns. Ticket_id (Primary key, Int) Attachment1
I have a table which has a NVARCHAR column, which could contain a GUID
if i have a table which has columns with fixed lenght, Will mySQL count
Suppose we have a table Users that has only one column UserId which is
I have a user table that has many columns, it looks roughly like this:
I have a table which has the following columns Id (int) UniqueId (string) CategoryId
I have a table which has 3 columns. Name , DateOfBirth , DateDeceded .
I need to update a column in a table which contains a lot of
i have a table which has many fields but i want to get count

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.