Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy table without primary key to another one

Tags:

sql

mysql

I want to copy one table to another one.

For example I have table Data(ID, time, serial_number...) and I have Temp_data(ID, time, serial_number...)

How to copy all items without primary key (ID).

I am using MYSQL, I have tried INSERT INTO Data SELECT * FROM Temp_data;

Problem is in primary key. both of the tables already have values and I need everything to be copied except ID.

like image 211
user123_456 Avatar asked May 28 '12 18:05

user123_456


1 Answers

Instead of SELECT *, spell out the columns that you want:

INSERT INTO Data (time, serial_number...)
  SELECT (time, serial_number...) FROM Temp_data;
like image 176
eggyal Avatar answered Sep 20 '22 16:09

eggyal