Ivan
Ivan

Reputation: 278

MySQL find which data inserted in which place

I want to know whether it is possible to find the row and column affected by an INSERT.

The data is read from a file and I want to avoid duplicates.

Upvotes: 0

Views: 53

Answers (4)

witchi
witchi

Reputation: 401

If you have unknown SQL statements which you will exceute in a batch process, you could parse on the fly your SQL statements to find out, which columns are used.

Upvotes: 0

LSerni
LSerni

Reputation: 57418

To avoid duplicates, just add appropriate INDEX UNIQUE clauses.

The closest thing to an "inserted row id" you can get with LAST_INSERT_ID() after declaring an appropriate AUTO_INCREMENT column key (thanks @mvp!).

If you use the INSERT IGNORE syntax, data will be automatically made unique, i.e., duplicate rows will be silently ignored and not inserted. You may also want to look at the ON DUPLICATE KEY... syntax for INSERT.

As for which columns are affected by an insert, that's easy -- all of them :-)

Upvotes: 1

CloudyMarble
CloudyMarble

Reputation: 37576

You can use the ServerLog to protocol statements, or set a trigger on all your tables which inserts protocols about all inserts in a Log table where you write the inserted columns/raws.

Upvotes: 0

Orangecrush
Orangecrush

Reputation: 1990

If you do not want the same data again, you could have a look at adding Primary Keys to your tables.

Upvotes: 0

Related Questions