Solved

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

Posted on 2016-07-28
7
37 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
ID: 41732921
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
ID: 41732923
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 2

Author Comment

by:srikotesh
ID: 41735760
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 VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41735868
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 2

Author Comment

by:srikotesh
ID: 41736240
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
ID: 41736432
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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41736459
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 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