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
 Table Structure

Author  Topic 

jobejufranz
Starting Member

33 Posts

Posted - 2008-02-28 : 04:35:47
Hi Guys,

I have another question.

Is there a query to display the structure of a certain table?
e.g. display the columns, data type,...etc.

TIA

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-02-28 : 04:44:59
try

exec sp_help <tablename>

or query using Information_Schema.Columns view (read about it in BOL)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-28 : 04:52:14
or

sp_columns 'table_name'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jobejufranz
Starting Member

33 Posts

Posted - 2008-02-28 : 05:38:50
Thanks PeterNeo and madhivanan

quote:
exec sp_help <tablename>


works but not

quote:
sp_columns 'table_name'


Incorrect syntax near 'sp_columns'.
Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-02-28 : 05:54:08
quote:
Originally posted by jobejufranz

Thanks PeterNeo and madhivanan

quote:
exec sp_help <tablename>


works but not

quote:
sp_columns 'table_name'


Incorrect syntax near 'sp_columns'.




sp_columns 'table_name'is working fine. check if you are having any dot (.) when running sp_columns 'table_name'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-28 : 06:08:33
You should have executed alone or with EXEC if there are multiple queries to run

Run this alone
sp_columns <tablename>

No errors

Now run with

exec sp_help <tablename>
sp_columns <tablename>

You get error

Againg run with

exec sp_help <tablename>
exec sp_columns <tablename>

No error


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jobejufranz
Starting Member

33 Posts

Posted - 2008-02-28 : 21:56:24
quote:
Originally posted by madhivanan

You should have executed alone or with EXEC if there are multiple queries to run

Run this alone
sp_columns <tablename>

No errors

Now run with

exec sp_help <tablename>
sp_columns <tablename>

You get error

Againg run with

exec sp_help <tablename>
exec sp_columns <tablename>

No error


Madhivanan

Failing to plan is Planning to fail



My sincere apology madhivanan, i was wrong.

Everything works perfectly.

Thanks a lot.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-29 : 05:27:30
<<My sincere apology madhivanan, i was wrong.>>

No problem

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -