Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Select Databases information

Posted on 2012-04-12
3
Medium Priority
?
188 Views
Last Modified: 2012-06-27
Is there a select or view that I could get that gets me the following for all NON system databases?

Such as if I had 2 catalogs....busSys and busUsers, I would get JUST the following for those two databases?

databasename     tablename     fieldname     fieldtype     isnull
0
Comment
Question by:lrbrister
  • 2
3 Comments
 
LVL 40

Expert Comment

by:lcohan
ID: 37839993
In SQL you can use

select * from sys.tables
select * from sys.columns

to get info about tables/columns in each user database
0
 
LVL 40

Accepted Solution

by:
lcohan earned 2000 total points
ID: 37840018
For instance code below will list all tables,columns, data type and precision/scale from current db where is executed :

select distinct
      c.id,
      o.name as 'Tname',
      c.name as 'Cname',
      t.name as DataType, c.length, c.xprec, c.xscale, c.isnullable--into #cp_tabless
from sysobjects o, syscolumns c, systypes t
where o.id = c.id and
          c.xtype = t.xtype and
            t.name <> 'sysname' and o.name not like 'sys%' and
        o.type = 'U'  
order by 'cname','tname'
0
 

Author Closing Comment

by:lrbrister
ID: 37857109
Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question