Solved

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

Posted on 2016-07-28
7
31 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
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 1

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 142

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 1

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 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate report pulling data (links) from three tables 31 59
MySQL Error 3 40
Using winfows 7 and 10 download en install MYSQL server from a batch 13 105
Amazon Redshift 2 28
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…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 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

22 Experts available now in Live!

Get 1:1 Help Now