Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2016-07-28
7
Medium Priority
?
46 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 400 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 30

Accepted Solution

by:
Olaf Doschke earned 1600 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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 30

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

604 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