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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to get all columns of database ?

Author  Topic 

hdv212
Posting Yak Master

140 Posts

Posted - 2008-04-21 : 16:57:09
hi
i want to get all columns of database, i use this code to do this :
select * from information_schema.columns

this script works good,but return columns for all tables and views and i don't views, i want only columns for user tables, also i don't know how to filter this result to remove views, can anybody help me ?
thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2008-04-21 : 17:28:44
where table_name in (select table_name from information_schema.tables where table_type = 'base_table')


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-21 : 17:29:37
select c.*
from information_schema.columns c
inner join information_schema.tables t
on c.table_name = t.table_name
where t.table_type = 'base table'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-04-21 : 17:53:48
The two solutions posted above should also include a join on column TABLE_SCHEMA, in case there are tables not owned by DBO in the database.

Here is another solution without a join. This must be run in the database you are interested in.

Use MyDB
select
*
from
information_schema.columns a
where
object_id(quotename(a.TABLE_SCHEMA)+'.'+quotename(a.TABLE_NAME),'U') is not null
order by
a.TABLE_SCHEMA,
a.TABLE_NAME,
a.ORDINAL_POSITION






CODO ERGO SUM
Go to Top of Page

hdv212
Posting Yak Master

140 Posts

Posted - 2008-04-22 : 02:54:00
very very thanks.
Go to Top of Page
   

- Advertisement -