How to duplicate easily a record in mysql

I wanted to duplicate a record on my database and the first problem was the primary key.
I couldn’t directly after my INSERT statement put my SELECT because of the primary key..

So here is my solution (theorical):
CREATE TEMPORARY TABLE [your temporary table] SELECT * FROM [the table where you have the row to duplicate] [where statement if you have any];
update [your temporary table] set [your primary key] = «  »;
INSERT INTO [your new table] SELECT * FROM [your temporary table]

In my case it looks like:
CREATE TEMPORARY TABLE temp_tb SELECT * FROM mytable where myid = 12;
update temp_tb set myid = «  »;
INSERT INTO mytable SELECT * FROM temp_tb

On insert you can put another table, in my case I wanted to duplicate a row in the same table.

How to add a symbolic link in Windows 7

I wanted several times to do, like on my linux installation, a symbolic link. For people who’s don’t know I’ll explain a bit.
When you read some tutorials about mysql, for example, you will probably find something like:
mysql -u root …..
You need to go to mysql folder to do this command.
The symbolic link allows you to directly write on your prompt « mysql » and the command line will make the link between your command and the mysql.exe. (or any other .exe)

To do this you have to:

– Go on Start Menu
– Seek for Computer
– Right click on it, then Properties
– Choose Advanced system settings
– Go on Advanced tab
– Click on Environment Variables…
– Edit the Path variable
– Add the folder where you have your mysql (for me it’s: C:\wamp\bin\mysql\mysql5.5.24\bin\ so I add:
;C:\wamp\bin\mysql\mysql5.5.24\bin\

Don’t forget the ; before and the backslash at the end.
Then ok, close the window.

Now open a prompt and you should be able to write mysql command everywhere.

If you prefeir to choose another word like sqlvar, you can do as well:
mklink name repository

For our example:
mklink sqlvar C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe