I want to export a tablet with a lot of columns (20+). I want to exclude the primary key, but don't want to write SELECT column2
,column3
and so on for all the rest columns. I want to export the data without primary key so when I import it, the primary key will be auto incremented. I am using MySql and PhpMyAdmin.
Asked
Active
Viewed 3,190 times
1

Kristiyan Katsarov
- 65
- 1
- 9
-
Mmmh, why not just use the `SHOW COLUMNS FROM my_table;` function and copy the output of that into your query. So you don't have to type all the columns. – Chief Wiggum Nov 10 '14 at 10:51
-
You can't do this directly with, instead i suggest you export it the normal way then use NotePad++ and regular expressions to remove the primary key column – osmancode Nov 10 '14 at 10:56
1 Answers
1
See this answer found in select-all-columns-except-one-in-mysql:
SET @sql = CONCAT('SELECT ', (SELECT REPLACE(GROUP_CONCAT(COLUMN_NAME), '<columns_to_omit>,', '') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '<table>' AND TABLE_SCHEMA = '<database>'), ' FROM <table>');
PREPARE stmt1 FROM @sql;
EXECUTE stmt1;
This helped me a lot on a simmilar problem.