How to list all tables in MSSQL?

I use the code below to show tables in my database.

I get "Connected to a database", but nothing else. Is my code correct? Can I use another way to get the information I need?

<?php $link = mssql_connect('HOST', 'user', 'pass'); if (!$link || !mssql_select_db('dbname', $link)) { die('Unable to connect or select database!'); }else{ echo"Connected to database"; } $v = mssql_query("Select name from sysobjects where type like 'u'"); $row = mssql_fetch_array($v); echo "<br>"; echo $row[0]; echo "<br>"; mssql_free_result($v); ?> 
+4
source share
2 answers

Alternative method also selects a schema name

 SELECT TABLE_CATALOG , TABLE_SCHEMA , TABLE_NAME , TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES 
+10
source
 SELECT * FROM sys.Tables; 

Gotta do the magic: -D

And if u wants to see all the columns, I would do

 SELECT TOP 1 * From Tablename; 

so you will have one row with all columns, its not perfect, but it does the trick if you just want to know sth

+3
source

Source: https://habr.com/ru/post/1347079/


All Articles