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 Description

Author  Topic 

madhan
Yak Posting Veteran

59 Posts

Posted - 2011-12-24 : 08:04:34
Hi,

Sorry for the very newbie question. I have tried googling about this question but no luck. how to find out table column description(datatype, column name etc) by code without using table designer.

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-24 : 08:06:29
[code]SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='Your Table Name here'[/code]

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

Go to Top of Page

madhan
Yak Posting Veteran

59 Posts

Posted - 2011-12-24 : 08:07:48
Thanks! That was very quick response!!
Go to Top of Page

madhan
Yak Posting Veteran

59 Posts

Posted - 2011-12-24 : 08:35:00
select * from tempdb.INFORMATION_SCHEMA.TABLES

the previous query displayed all info.but


use AdventureWorks2008;
GO
select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='Person.Person'


I got only empty Information_schema information. But table designer displayed table column and data type. please help me again.


Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-12-24 : 08:56:51
Query sys.tables and sys.columns, you may also need sys.types.

Or, in your query, filter for Table_Name='Person'
The table is not named Person.Person. It's the table called Person in the schema called Person.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-24 : 09:22:24
quote:
Originally posted by madhan

select * from tempdb.INFORMATION_SCHEMA.TABLES

the previous query displayed all info.but


use AdventureWorks2008;
GO
select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='Person.Person'


I got only empty Information_schema information. But table designer displayed table column and data type. please help me again.





it should be

use AdventureWorks2008;
GO
select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='Person'
AND TABLE_SCHEMA = 'Person'


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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-27 : 08:10:20
or

EXEC sp_help 'table name'

Madhivanan

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

- Advertisement -