Home > other >  Sql query to return column name, data type, data length, if a column is null
Sql query to return column name, data type, data length, if a column is null

Time:03-04

I have the following query:

SELECT column_name,
   data_type
   date_length
FROM   information_schema.columns
WHERE  table_schema = ’bookidz_ro_dev’
AND    table_name = ’rack_level’;

And I get this error: #1054 - Unknown column '’bookidz_ro_dev’' in 'where clause' even though the db name is correct and so is the table name.

CodePudding user response:

As i tested your code is good, but those ’ quotations are not correct.

SELECT 
*
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE  TABLE_SCHEMA = 'bookidz_ro_dev'
AND    TABLE_NAME = 'rack_level';

I used * because there is no Date_Length column in information_schema.columns

CodePudding user response:

Looks like You are using wrong quotations, try it with correct one:

SELECT column_name,
   data_type
   date_length
FROM   information_schema.columns
WHERE  table_schema = 'bookidz_ro_dev'
AND    table_name = 'rack_level';
  • Related