MySQL Forums
Forum List  »  Newbie

Re: Copy entire table
Posted by: Frank Thomson
Date: January 05, 2022 01:45AM

Thanks Peter. Greatly appreciated.
The key was to explicitly name the fields as you showed in your line:
"insert into newtbl(cola,colb,colc,...)"

> CREATE TABLE new_table ( id INT(11) NOT NULL AUTO_INCREMENT , PRIMARY KEY (id)) ;
Query OK, 0 rows affected (0.12 sec)

> INSERT INTO new_table SELECT * FROM employees;
ERROR 1136 (21S01): Column count doesn't match value count at row 1

> ALTER TABLE `new_table` ADD `employee_number` INT(11) NOT NULL AFTER `id`, ADD `employee_name` VARCHAR(100) NOT NULL AFTER `employee_number`;
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0

> INSERT INTO new_table(employee_number,employee_name) SELECT * FROM employees;
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0

Options: ReplyQuote




Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.