Solved

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

Posted on 2016-07-28
7
42 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

687 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