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
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