Hello @Sarvesh Pandey ,
Thanks for the ask and using the forum .
If the ask is just to exclude the PK column , you can reference the below query and make adjustment to your query ,hope fully it helps .
CREATE TABLE dbo.footest2
(
id int identity(1,1)
,name varchar(100)
,state varchar(100)
,primary key (id)
)
**select c.name from sys.columns C
JOIN sys.tables T
on C.object_id = t.object_id
where t.name ='footest2'
and c.name not in (select column_name from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
where TABLE_NAME =t.name )**
Thanks Himanshu
Please do consider to click on "Accept Answer" and "Up-vote" on the post that helps you, as it can be beneficial to other community members