ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   List of tables in SQL server database (https://www.excelbanter.com/excel-programming/440715-list-tables-sql-server-database.html)

Madiya

List of tables in SQL server database
 
Hi,
How do I list all user tables in a SQL Server database?
Once done I have to passon some commends also to all the listed
tabled.

I already have connection strings and also able to extract records as
pe the criteria from one defined table but do not know how to loop
thru the tables or table properties.

Any pointers are appreciated.

Regards,
Madiya

Bob Phillips[_4_]

List of tables in SQL server database
 
Try this

Set oConn = CreateObject("ADODB.Connection")
oConn.Open sConnString
Set oCat = CreateObject("ADOX.Catalog")
Set oCat.ActiveConnection = oConn

iRow = 1
For Each tbl In oCat.Tables
If (tbl.Type < "SYSTEM TABLE") Then
sTableName = tbl.name
cLength = Len(sTableName)
iTestPos = 0
iStartpos = 1
Debug.Print sTableName
End If
Next tbl

oConn.Close
Set oCat = Nothing


--

HTH

Bob

"Madiya" wrote in message
...
Hi,
How do I list all user tables in a SQL Server database?
Once done I have to passon some commends also to all the listed
tabled.

I already have connection strings and also able to extract records as
pe the criteria from one defined table but do not know how to loop
thru the tables or table properties.

Any pointers are appreciated.

Regards,
Madiya




Madiya

List of tables in SQL server database
 
On Mar 17, 9:43*am, Madiya wrote:
Hi,
How do I list all user tables in a SQL Server database?
Once done I have to passon some commends also to all the listed
tabled.

I already have connection strings and also able to extract records as
pe the criteria from one defined table but do not know how to loop
thru the tables or table properties.

Any pointers are appreciated.

Regards,
Madiya


Somebody working with VBA and SQL?

Bob Phillips[_4_]

List of tables in SQL server database
 
Yes, I posted a reply yesterday.


Bob

"Madiya" wrote in message
...
On Mar 17, 9:43 am, Madiya wrote:
Hi,
How do I list all user tables in a SQL Server database?
Once done I have to passon some commends also to all the listed
tabled.

I already have connection strings and also able to extract records as
pe the criteria from one defined table but do not know how to loop
thru the tables or table properties.

Any pointers are appreciated.

Regards,
Madiya


Somebody working with VBA and SQL?



Madiya

List of tables in SQL server database
 
On Mar 18, 8:29*pm, "Bob Phillips" wrote:
Yes, I posted a reply yesterday.

Bob

"Madiya" wrote in message

...
On Mar 17, 9:43 am, Madiya wrote:

Hi,
How do I list all user tables in a SQL Server database?
Once done I have to passon some commends also to all the listed
tabled.


I already have connection strings and also able to extract records as
pe the criteria from one defined table but do not know how to loop
thru the tables or table properties.


Any pointers are appreciated.


Regards,
Madiya


Somebody working with VBA and SQL?


Bob,
Thanks but I could not find your reply.
Can you Pl post back here or give me link to that msg pl.

Regards,
Madiya

Bob Phillips[_4_]

List of tables in SQL server database
 
This was it.

Try this

Set oConn = CreateObject("ADODB.Connection")
oConn.Open sConnString
Set oCat = CreateObject("ADOX.Catalog")
Set oCat.ActiveConnection = oConn

iRow = 1
For Each tbl In oCat.Tables
If (tbl.Type < "SYSTEM TABLE") Then
sTableName = tbl.name
cLength = Len(sTableName)
iTestPos = 0
iStartpos = 1
Debug.Print sTableName
End If
Next tbl

oConn.Close
Set oCat = Nothing




--

HTH

Bob

"Madiya" wrote in message
...
On Mar 18, 8:29 pm, "Bob Phillips" wrote:
Yes, I posted a reply yesterday.

Bob

"Madiya" wrote in message

...
On Mar 17, 9:43 am, Madiya wrote:

Hi,
How do I list all user tables in a SQL Server database?
Once done I have to passon some commends also to all the listed
tabled.


I already have connection strings and also able to extract records as
pe the criteria from one defined table but do not know how to loop
thru the tables or table properties.


Any pointers are appreciated.


Regards,
Madiya


Somebody working with VBA and SQL?


Bob,
Thanks but I could not find your reply.
Can you Pl post back here or give me link to that msg pl.

Regards,
Madiya




All times are GMT +1. The time now is 09:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com