Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 18th, 2005, 02:15 AM
Authorized User
 
Join Date: Nov 2004
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
 
Old January 18th, 2005, 07:41 AM
Friend of Wrox
 
Join Date: Nov 2003
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
 
Old January 18th, 2005, 07:48 AM
Friend of Wrox
 
Join Date: Nov 2003
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.