Skip to content

Instantly share code, notes, and snippets.

@RafaAguilar
Created January 31, 2016 03:57
Show Gist options
  • Save RafaAguilar/7986a1a8755ed21609ee to your computer and use it in GitHub Desktop.
Save RafaAguilar/7986a1a8755ed21609ee to your computer and use it in GitHub Desktop.
Obtain _not null_ and with no _default value_ fields of a table (useful when you need an _INSERT_ test statement of a big table)
SELECT
COLUMN_NAME AS `Field`
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'schemaName'
AND TABLE_NAME = 'tableName'
AND IS_NULLABLE = 'NO'
AND (COLUMN_DEFAULT IS NULL
OR COLUMN_DEFAULT = '')
LIMIT 200;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment