Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 query for checking no of fields in database table

Author  Topic 

prakashsnkr
Starting Member

1 Post

Posted - 2010-02-11 : 01:20:19
Hi all,
I am a new one for sql i need to know what is the query for checking no of fields in database table.
Actually(no of fields) it may vary depends on user profiles.
Any help please let me know as early as possible...

Thanks,
prakash.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-11 : 01:46:35
quote:
what is the query for checking no of fields in database table


select count(*)
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'table name'


quote:
Actually(no of fields) it may vary depends on user profiles.

What do you mean by this ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 02:36:59
just in case same table exists in more than 1 schema, it would be safe to do


select count(*)
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'table name'
and TABLE_SCHEMA = 'your schema name'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-11 : 02:38:33
Good point there


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 02:40:48
quote:
Originally posted by khtan

Good point there


KH
[spoiler]Time is always against us[/spoiler]




We had a similar situation where a table existed in dbo as well as local schema of developers thats why it striked me

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -