Get the table on the database

Hi Experts, I wish to obtain all Tables that is inside my database. I want to get their names and put it in the table. I have code below but I have no idea how do it. I have DataBase named, "MyDataBase"

<%

response.expires=-1

Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")

cn.ConnectionString = "driver={SQL Server};server=MyNoteBook\SQLEXPRESS;uid=sa;pwd=sa;database=" & "MyDataBase" & ""
cn.Open

%>

Open in new window

Whing Dela CruzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MishaProgrammerCommented:
tre this code:
SELECT TABLE_NAME FROM MyDataBase.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'

Open in new window

1
Whing Dela CruzAuthor Commented:
Hi Misha, How could I correct this code? This code is base on your suggested above.

   Set rs = cn.Execute("SELECT TABLE_NAME FROM MyDataBase.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='" & "BASE TABLE" & "'")
           with rs
               If rs.BOF = True Then 'Not exist
         		    response.write("Database is not exist")
         			 response.end()
               Else
                  do until rs.EOF
                     if msg = "" then
                         msg = trim(rs("BASE TABLE"))
                     else
                        msg = msg & "/" & ( trim(rs("BASE TABLE"))) 
                     end if  
                     rs.MoveNext
                  loop

                  response.write(msg)
                  response.end()
                  cn.close
               end if
           End with

Open in new window

0
MishaProgrammerCommented:
Does this code work? Or not?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Whing Dela CruzAuthor Commented:
It's working sir, I just changed the "trim(rs("BASE TABLE"))" to trim(rs("TABLE_NAME"))  now perfectly working. However, before I close this question, is there any tricks here to show the table alphabetically, base on the code above?
0
MishaProgrammerCommented:
No problem, you can use "order by".
SELECT TABLE_NAME FROM MyDataBase.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' order by TABLE_NAME 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MishaProgrammerCommented:
Also you can sorted result in  decrease
SELECT TABLE_NAME FROM Test1.INFORMATION_SCHEMA.TABLES
 WHERE TABLE_TYPE = 'BASE TABLE' order by TABLE_NAME desc

Open in new window

0
Whing Dela CruzAuthor Commented:
Thanks a lot sir, every code you have given me are working and help me a lot...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.