Wrox Programmer Forums
|
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 December 15th, 2003, 03:16 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default Return all Tables?

How can I show all the tables in a database? I want to see every table but I don't have access to the server tools. I use asp to work with the database I would like to see every table that's there.

Thanks

__________________
-----------------------------------------------------------
\"Don\'t follow someone who\'s not going anywhere\" John Mason
 
Old December 15th, 2003, 03:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Look at the INFORMATION_SCHEMA.TABLES system view, e.g.
Code:
SELECT * FROM INFORMATION_SCHEMA;
will display a list of all the tables in the current database. The column TABLE_TYPE will indicate whether the table is a BASE_TABLE or a VIEW.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old December 15th, 2003, 03:44 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SQLStr="SELECT * FROM INFORMATION_SCHEMA"

I use this but I get an error "Invalid object name"

Thanks for the response

 
Old December 15th, 2003, 03:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sorry. The view name is INFORMATION_SCHEMA.TABLES. The code should read:
Code:
SELECT * FROM INFORMATION_SCHEMA.TABLES

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old December 15th, 2003, 03:57 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, it works great

 
Old March 3rd, 2005, 01:38 PM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can any one help how to write asp script that display a table from sql server using select * from information_schema.tables

 
Old March 3rd, 2005, 08:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Method,
I see the connection but when you ask a new question it is best to start a new topic.

To display table data from select query recordset you can:

Code:
sql_string = "select * from TABLENAME"
'===========================================================================================================================
'AREA BELOW DOES NOT NEED TO BE CHANGED, JUST CHANGE THE SQL STRING ABOVE                                                   
'===========================================================================================================================
Response.write("=============================================<BR>")
Response.write("This page displays the results for the query:<BR>")
Response.write(sql_string & "<BR>")
Response.write("=============================================<BR>")
set recordset = objDBConn.execute(sql_string)

'Has been modified to print a table with the 
'table fields as headers and then the records to follow
'Just need to change the sql_string above
If Not recordset.EOF And Not recordset.BOF Then
    count = 0 
    wt = 0
    cub = 0
    response.write "<table border=1><tr>"
    For i = 0 To recordset.Fields.Count - 1
       response.write "<td><b>" & recordset(i).Name  & "</b></td>"
    Next
    response.write "</tr>"
    while not recordset.eof
        response.write "<tr>"            
        For i = 0 To recordset.Fields.Count - 1
            if (not isnull(recordset(i).Value)) then 
                response.write "<td>" & recordset(i).Value  & "</td>"
            else
                response.write "<td>&nbsp;</td>"
            end if
        Next            
        response.write "</tr>"
        count = count + 1
        recordset.movenext
    wend
    response.write "</table>"
else
    response.write "No Matches"    
End If
response.write "<br>Total Records: " & count & "<br><br>"
response.write "...Completed"


recordset.close

objDBConn.close 
'================================================================================================================================
======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old March 7th, 2005, 08:32 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rodmcleay
 Method,
I see the connection but when you ask a new question it is best to start a new topic.

To display table data from select query recordset you can:

Code:
sql_string = "select * from TABLENAME"
'===========================================================================================================================
'AREA BELOW DOES NOT NEED TO BE CHANGED, JUST CHANGE THE SQL STRING ABOVE                                                   
'===========================================================================================================================
Response.write("=============================================<BR>")
Response.write("This page displays the results for the query:<BR>")
Response.write(sql_string & "<BR>")
Response.write("=============================================<BR>")
set recordset = objDBConn.execute(sql_string)

'Has been modified to print a table with the 
'table fields as headers and then the records to follow
'Just need to change the sql_string above
If Not recordset.EOF And Not recordset.BOF Then
    count = 0 
    wt = 0
    cub = 0
    response.write "<table border=1><tr>"
    For i = 0 To recordset.Fields.Count - 1
       response.write "<td><b>" & recordset(i).Name  & "</b></td>"
    Next
    response.write "</tr>"
    while not recordset.eof
        response.write "<tr>"            
        For i = 0 To recordset.Fields.Count - 1
            if (not isnull(recordset(i).Value)) then 
                response.write "<td>" & recordset(i).Value  & "</td>"
            else
                response.write "<td>&nbsp;</td>"
            end if
        Next            
        response.write "</tr>"
        count = count + 1
        recordset.movenext
    wend
    response.write "</table>"
else
    response.write "No Matches"    
End If
response.write "<br>Total Records: " & count & "<br><br>"
response.write "...Completed"


recordset.close

objDBConn.close 
'================================================================================================================================
======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
Thank u for reply . But what i meant is using
SELECT * FROM INFORMATION_SCHEMA.TABLES.I do not see any usage of meta data here!i mean information about tables , columns,datatype , primary keys and foreign keys should not be hardcoded. for example i want to write and asp script that uses meta data of northwind database and display all records of Customers tables.Thanks and looking forward for u reply. Since i realy need to learn this meta data usage well .Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Save and Return hdpark BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 December 2nd, 2008 02:14 PM
need some help please getting a return value merk ASP.NET 2.0 Basics 4 October 3rd, 2007 07:10 PM
How to get value when procedure return value akumarp2p SQL Server 2000 2 May 29th, 2007 11:30 AM
creating tables within tables in access??? carswelljr Access 3 August 23rd, 2006 01:21 PM
Return an arraylist Morrislgn VB.NET 2002/2003 Basics 1 March 24th, 2006 04:42 AM





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