- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetColumnNamesFromTable.sql
More file actions
Latest commit
16 lines (13 loc) · 568 Bytes
/
Copy pathgetColumnNamesFromTable.sql
File metadata and controls
16 lines (13 loc) · 568 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- +------------------------------------------------------
-- + Get a CSV of columns in a table
-- + Author: Simon Rogers
-- + Date: 7th January 2016
-- + SQL: mysql
-- +------------------------------------------------------
SET @@group_concat_max_len =1000000;
SET @table_name ='<table_name>';
SELECT @table_name as`table`, trim(group_concat(concat('\'',column_name,'\''))) as`columns`
FROMinformation_schema.columns
WHERE table_name = @table_name
and column_name NOT IN ('id', 'created_at', 'updated_at', 'deleted_at')
ORDER BY table_name,ordinal_position;