Richard
Richard

Reputation: 15862

how to get field name types from a sql database

To get field names one would use the command:

select column_name from information_schema.columns where table_name='person'; 

My question is how would one also get the field types in a similar list?

Upvotes: 7

Views: 9772

Answers (5)

zinderud
zinderud

Reputation: 63

al shema

SELECT table_name, column_name ,column_type FROM information_schema.columns WHERE table_schema = 'shema name'

Upvotes: 0

If we want both column_name & column_type or Data Type: select column_name, column_type from information_schema.columns where table_name='personal_info';

If we want only column_name:

select column_name from information_schema.columns where table_name='personal_info';

If we want only column_type: select column_type from information_schema.columns where table_name='personal_info';

Upvotes: 0

Ben S
Ben S

Reputation: 69342

SELECT
    column_name,
    column_type    # or data_type 
FROM information_schema.columns 
WHERE table_name='person'; 

Schema Info

Upvotes: 16

Gratzy
Gratzy

Reputation: 9389

SELECT
    column_name,
    data_type
FROM information_schema.columns 
WHERE table_name='person';

Upvotes: 0

Mark Baker
Mark Baker

Reputation: 212412

select column_name,
       column_type 
  from information_schema.columns 
 where table_name='person';

Upvotes: 0

Related Questions