Wednesday, March 7, 2012

How to count the columns of a table

Is there an easy way to count the columns of a table in T-SQL?
Thanks for your help
SaschaTry:
select
count (*)
from
information_schema.columns
where
table_name = 'MyTable'
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
.
"Sascha A. Koenig" <spam@.thekoenigs.info> wrote in message
news:u508YasHFHA.3612@.TK2MSFTNGP09.phx.gbl...
Is there an easy way to count the columns of a table in T-SQL?
Thanks for your help
Sascha|||Any of these below queries can help you:
select * from information_schema.columns where table_name = 'authors'
(or)
select count(*) from syscolumns where id = object_id('authors')
Regards,
Jagan
"Sascha A. Koenig" wrote:

> Is there an easy way to count the columns of a table in T-SQL?
> Thanks for your help
> Sascha
>
>|||Thanks a lot!!!
Sascha
"Jagan Mohan" <Jagan Mohan@.discussions.microsoft.com> wrote in message
news:4CE50DDE-BC69-4461-9B0A-0B4C39FF6616@.microsoft.com...
> Any of these below queries can help you:
> select * from information_schema.columns where table_name = 'authors'
> (or)
> select count(*) from syscolumns where id = object_id('authors')
> Regards,
> Jagan
> "Sascha A. Koenig" wrote:
>

No comments:

Post a Comment