Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 18th, 2005, 02:15 AM
Authorized User
 
Join Date: Nov 2004
Location: mumbai, maharashtra, India.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query database for List of tables & other details

hi techies..

I want to get a generalised sql query.. for any database.. that will list me..all the table names and their fields,datatype,length, nullable/not at one go.. in SQL 2000 Server..

I have worked out the following query..

"Select a.name as tablename, b.name as fieldname, b.length
from sysobjects a,
syscolumns b where a.xtype ='U' and a.id = b.id order by a.name"

but.. the result is not completely satisfying..

pls..support..
suneeta
__________________
.Net developer
Reply With Quote
  #2 (permalink)  
Old January 18th, 2005, 07:41 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

try this

Code:
SELECT 
isc.table_name, 
isc.column_name, 
isc.data_type, 
COALESCE(isc.character_maximum_length, isc.numeric_precision),
si.rowcnt
FROM information_schema.columns isc
INNER JOIN information_schema.tables ist
ON isc.table_name = ist.table_name
INNER JOIN sysindexes si
ON isc.table_name = OBJECT_NAME(si.id)
WHERE ist.table_type = 'base table'
AND ist.table_name not like 'dt%'
AND si.indid IN (0,1)
ORDER BY isc.table_name, isc.column_name
Jaime E. Maccou
Reply With Quote
  #3 (permalink)  
Old January 18th, 2005, 07:48 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

or you can also do it this way. add or delete columns as you see fit. know you the tables where to get the data.

Code:
SELECT isc.table_name, isc.column_name, isc.data_type
FROM   information_schema.columns isc
       INNER JOIN information_schema.tables ist
            ON isc.table_name = ist.table_name
WHERE  OBJECTPROPERTY(OBJECT_ID(ist.table_name), N'IsUserTable') = 1 
AND    OBJECTPROPERTY(OBJECT_ID(ist.table_name), N'IsMSShipped') = 0
AND    DATA_TYPE NOT IN ('text', 'ntext', 'image')
ORDER BY isc.table_name, isc.column_name


Jaime E. Maccou
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
List tablesname from database & list databasename ittorget MySQL 3 September 10th, 2005 03:06 AM
Retrieving the list of tables from a database devi.g@india.com J2EE 0 February 2nd, 2005 09:54 PM
Copy Header and Details to similar tables Mitch Access 2 February 2nd, 2005 07:34 PM
Retrieving list of tables inside a database... vb_developer SQL Server ASP 6 September 13th, 2004 10:47 AM
Lists of All Inserts & Updates Tables in Database Walden SQL Server 2000 1 October 24th, 2003 09:47 AM



All times are GMT -4. The time now is 02:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.