This is my code:
Server server = new Server(new ServerConnection(con));
server.ConnectionContext.Connect();
foreach (Table table in server.Databases[sqlDatabase].Tables)
{
if (table <is a base table>)
Basically this pulls back views as well I think. The SQL I use to identify the wanted tables is:
SELECT TABLE_NAME FROM MyDatabase.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'
However there doesn't seem to be a TABLE_TYPE
property on the results which are Microsoft.SqlServer.Management.Smo.TableCollection
. According to SQL, the TABLE_TYPE is either BASE TABLE
or VIEW
so only two possibilities.
How can I identify only tables (and not views)?