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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:00:46+00:00 2026-06-12T06:00:46+00:00

I need to fetch data from database for backup in the form of insert

  • 0

I need to fetch data from database for backup in the form of insert statements

I need to do it on a button click in c#. So i think an sql query or stored procedure will be appropriate to do this, rather than mysqldump.

Secondly I need them for all tables. Instead of writing table and column names. They should be fetched from information_schema, because the query will not need to be changed for different scema

If there already exists a solution, please guide me.

Update : I have prepared a solution, it is posted, still looking for the better one.

  • 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-12T06:00:47+00:00Added an answer on June 12, 2026 at 6:00 am

    To get Data of whole database – SqlFiddle Demo


    To get data of only one table – – SqlFiddle Demo

    I have made a complex but acceptable solution. But needs improvement.

    This is a complex procedure with complex coding especially the query which fetches all rows of all columns into a single result by group_concat and formats with a complex concatenation.

    Need it simplified, efficient and working in all scenarios.

    Some details of my solution : Following is the important part, other is just conditions/Looping (I am not handy with documentation also it needs time and suggestions, someone might help me in its formatting and improvement, Sorry for any inconvenience, however I will be glad for any help from you and me)

    Note: group_concat(yourColumn separator ‘ –anySeparator– ‘) is merging all rows of your column as one such that Rows are separated by –anySeparator–

    select group_concat(column_name separator '`,`') into @cns1 from
    information_schema.columns where table_schema=dn and table_name=@tn;
    

    1 : column_names are got as a single value separated by

    `,` => @cs1 = id`,`ename`,`did
    
    select group_concat(column_name separator '`,"\',\'",`') into @cns2
    from information_schema.columns where table_schema=dn and table_name=@tn;
    

    2 : column_names are got as a single value separated by

    `','` => @cn2  = id`','`ename`','`did
    
    set @cns1=concat("`",@cns1,"`");    set @cns2=concat("`",@cns2,"`");
    

    3: Missing letter (`) is put at beginning and end of Column names

    set @res=concat(@res," insert into ",@tn,"(",@cns1,") values ('");
    

    4: Simply makes res= " insert into emp(`id` , `ename` ,`did` ) values(" Here you can see why have I put separators (MySql Formatting is achieved)

    set @temp := '';
    set @q := concat("select group_concat(concat(",@cns2,") separator \"'),('\")
     from ",dn,".",@tn, " into @temp");
    

    Above is the most crucial statement It gets all data rows from table as rows of a single column and further these rows are merged being separated by '),('

    5.1 concat(",@cns2,") gets values of all columns in a single one.

    5.2 After outer most concat now @q is

     @q = "select group_concat(`id`','`ename`','`,did` separator '),(' from 
    mydb.emp into @temp";
    

    5.3 : group_concat will merge all rows of that combined column into one value.
    Columns values will be joined through separators existing in @cns2 and rows level joining will be with '),('

    prepare s1 from @q;
    execute s1;deallocate prepare s1;
    set @res = concat(@res,@temp,");");    
    

    @q is executed

    set @res = concat(@res,@temp,");");
    

    6 : And We will get result as

     res was = insert into emp(`id`,`ename`,`did`) values ('
    @temp = 1','e1','4'),('2','e2','4'),
    ('3','e3','2'),('4','e4','4'),('5','e5','3
    

    And after @res = concat(@res,@temp,");"); we get

     insert into emp(`id`,`ename`,`did`) values ('1','e1','4'),('2','e2','4'),
    ('3','e3','2'),('4','e4','4'),('5','e5','3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We need to fetch data from a database using LINQ. We now need to
I have a query that simply fetch data from my database, this query returns
I need to fetch data from normalized MSSQL db and feed them in Solr
Im using vb.net and I need to fetch data from two different tables and
What do I do, I need to fetch data from 3 tables in mysql,
Lets say I need to fetch some records from the database, and filter them
I want to create my own RSS/XML feed. I fetch data from the database
I am getting query from database. Using that query I need to run that
I need to fetch images and some other data from server and then display
Possible Duplicate: how to delete item from listView? I fetch data from Database in

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.