Created
March 26, 2019 13:12
-
-
Save olivertappin/245f8f3d612e4dabef836cf35000e6f4 to your computer and use it in GitHub Desktop.
Return the column entry for a SHOW CREATE TABLE (based on primary key or column name)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT RTRIM(CONCAT( | |
'`', | |
COLUMN_NAME, | |
'`', | |
' ', | |
COLUMN_TYPE, | |
' ', | |
IF (COLLATION_NAME IS NULL, '', CONCAT('COLLATE ', COLLATION_NAME, ' ')), | |
IF (IS_NULLABLE = 'YES', '', 'NOT NULL '), | |
IF (COLUMN_DEFAULT IS NULL, '', CONCAT('DEFAULT ', COLUMN_DEFAULT, ' ')), | |
IF (IS_NULLABLE = 'YES' AND COLUMN_DEFAULT IS NULL, 'DEFAULT NULL ', ''), | |
EXTRA | |
)) AS `SQL` | |
FROM information_schema.columns | |
WHERE | |
TABLE_NAME = 'TABLE' | |
AND TABLE_SCHEMA = 'DATABASE' | |
AND COLUMN_KEY = 'PRI' | |
# AND COLUMN_NAME = 'COLUMN' | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment