About Me

My photo
Mumbai, Maharastra, India
He has more than 7.6 years of experience in the software development. He has spent most of the times in web/desktop application development. He has sound knowledge in various database concepts. You can reach him at viki.keshari@gmail.com https://www.linkedin.com/in/vikrammahapatra/ https://twitter.com/VikramMahapatra http://www.facebook.com/viki.keshari

Search This Blog

Thursday, December 30, 2010

Getting column/field list in sql server table

How to get list of fields under a table


It is very simple to get list of fields or column under a sql server table. With the help of sys object we can get the column list. Here is an example:

select * from syscolumns where id =
(select id from sysobjects where type='U' and name like 'SSC_School1')

OR

select * from syscolumns where id =
(select object_id from sys.objects where type='U' and name like 'SSC_School1')

OR


select * from sys.columns where object_id =
(select object_id from sys.objects where type='U' and name like 'SSC_School1')

Here 1) type refer to object (sql server object like table, sp etc) and 'U' refer to user defined table
2) name refer to your Table name.


Post Reference: Vikram Aristocratic Elfin Share

No comments:

Post a Comment