Solved

How to get the insertquery from the table for a specific id in mysql

Posted on 2016-07-28
7
28 Views
Last Modified: 2016-07-31
Hi Experts,

I have a tabel called text,having 50 columns
I have inserted one record to this table long back.
if i want to see the same insert query how do i get from the table.
0
Comment
Question by:srikotesh
  • 3
  • 2
  • 2
7 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
Comment Utility
you can generate a INSERT statement using mysqldump:
http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html
using the --tables (to limit to this table)
using the --where (to limit to this ID)
eventually using  --complete-insert

this will not necessarly match 100% the statement as it was submitted, but generate a sql that will do the insert with the data as it is today
1
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 400 total points
Comment Utility
An insert stores data into a table. The data is stored, not the insert.

I don't quite understand what you want. To see your data you can simply SELECT * from text.

To insert a new row you'd write INSERT INTO text (col1, col2,...) VALUES ('val1','val2',...).
I can imagine you want to spare writing that lengthy thing, but it's indeed what you need. The database doesn't give you the insert, but the MySQL Workbench or phpMyAdmin both have tools to create an INSERT statement skeleton, so you only need to write the half of the statement with the list of values to insert.

Letting MySQL Workbench create an insert statement for you
This is how MySQL Workbench creates such an insert statement skeleton for you, to use in the Workbench itself or in PHP code.

Bye, Olaf.
0
 
LVL 1

Author Comment

by:srikotesh
Comment Utility
Hi Guy Hengel,

Can you provide the syntax to generate a insert statement.
from the above mysql link i didn't get the point.how to generate insert statement.
I dont know how to take a dump from the table as well.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
The suggestions are not about code, but about to manually generate the statement.
Please provide the background why you would want that be done from code?
0
 
LVL 1

Author Comment

by:srikotesh
Comment Utility
By using my sql work bench we are getting sql insert statements From the existing records.
if I have this insert statement I can change few of the values from that record I will inser New record.

here problem is
I am not using my sql work bench.
I am connecting to my sql sever from the cmd prompt.

is it possible to get the insert statement from the existing table or not?
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
No, not from the MySQL command line, this is a feature of the Workbench, not of MySQL itself.
The workbench makes use of SHOW COLUMNS to know what to build up as insert command. I heard of no database or any language capable writing out the code leading to some data. It's executing code, not generating it. That's always done by toolings around a database or language.

MySQLDump is indeed specialised on this, as it rather writes out the DDL and DML code to recreate a MySQL database and its data than export CSV, pure data, like other ETL tools do.

Bye, Olaf.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
and i think all you need to know is how to do this

insert into yourtable ( colA, colB, colC, colD )
select colA, colB, 456, 'abc'
from yourtable
where id = 987

colA and colB would be copied, colC and ColD with different data
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now