user628347 user628347 - 4 months ago 6
SQL Question

How can I select the primary key columns from a table?

I need to select the columns which is the primary key or the column which is not null. How can I do that?

And I want only the columns, not the values.

Answer
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS  
WHERE TABLE_NAME = '<TABLE_NAME>' and IS_NULLABLE = 'NO'