septaug septaug - 9 days ago 5
SQL Question

Filter tables beeing shown on combobox

I´ve been working on an app that lists all tables from sql database to allow some editing.
But not all tables should be visible.
Can anyone tell how to filter my query so that it only shows the desired tables?

the code i have now is:

con.Open();
using (SqlCommand com = new SqlCommand("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES", con))
{
using (SqlDataReader reader = com.ExecuteReader())
{
tabelas.Items.Clear();
while (reader.Read())
{
tabelas.Items.Add((string)reader["TABLE_NAME"]);
}
}
}


I think it should be something like

SELECT TABLES I WANT TO SHOW FROM INFORMATION_SCHEMA.TABLES


But in the
reader
what should i insert?

Thanks in advance,

Answer

In ORACLE this is how I would get a list of all tables that Start withj the Word ANALYSIS for Example

SELECT OBJECT_NAME
FROM ALL_OBJECTS
WHERE OBJECT_TYPE = 'TABLE'
AND OBJECT_NAME LIKE 'ANALYSIS%';

In SQL Server you could follow the same Construct

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_CATALOG LIKE'test%'

Or use the IN CLAUSE

SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_NAME IN ('t1','t2','t3' )