Access get all tables - sql

Is there a way in by sql statement or vba code to return all tables from access file? "I don't know the name of the tables"
like when you want to have all fields in a table you use '*' regardless the names of the fields.
but how to get all tables?!!!!

This will bring back all tables in the MS Access database (including linked tables)
SELECT MSysObjects.*, MSysObjects.Type
FROM MSysObjects
WHERE (((MSysObjects.Type)=1)) OR (((MSysObjects.Type)=6));
It also inclued Sys tables, so you might want to exclude tables starting with MSys
Have a look at
Using MSysObjects
SELECT "Table" AS [Table],
MSysObjects.Name, MSysObjects.

Depends what kind of database you are running. Many of them support the SHOW TABLES command.

Related

List visible databases in Teradata SQL Assistant?

I am working w the Teradata SQL Assistant. What I am trying to do, is to list all databases visible in the 'Database Explorer'. At first, I have tried simple query:
select DatabaseName from DBC.Databases;
but this returned thousands of databases I don't even have an access to. The DBC.Databases table seems not to have any field allowing me to filter results to only visible databases, or I am just unable to find it. And I am almost sure there is no such field in any table like '%database%'.
Is there any way to list those visible databases with SQL query?
Never use a system view without a trailing V or VX, those are old legacy views which will truncate object names over 30 characters.
In your case you need to switch to dbc.DatabasesVX, the X indicates that all objects where you don't have any access right are filtered automatically. But this might still return more databases than Database Explorer where you can add databases to the list manually.

How to find Oracle SYSTEMDB Tables

I have an existing database and sql queries.
The query below works and returns rows.
Select * from systemdb.TABLE_A;
However when I tried to find the "TABLE_A" table using "Oracle SQL Developer", I cannot find it in the Tables or Views tree list.
Would like to ask where can I possibly find this table?
What is the meaning of "systemdb" keyword in the query above?
Thank you very much.
In that query SYSTEMDB is the name of a schema in the database. A schema is almost synonymous with a user.
In SQL Developer you are presumably logged in as a different user than SYSTEMDB. To see the tables belonging to SYSTEMDB you expand "Other Users" at the bottom of the tree, then you find SYSTEMDB and expand that one, and then you can find "Tables" or "Views" of the user SYSTEMDB.
It seems to be a tablespace / user created by PeopleSoft PeopleTools. There is not much to be found on it, but I found it here:
have to prepare 4 environmets with PeopleSoft... If there any documentation when you create SystemDB?

dynamic from statement based on column name

Background info:
I got ms access 2010 database with >10 (and growing) linked tables, sources: csv & xls from scattered tools that needs to be combined and queried. The sources are 'dirty' and I use insert queries with additional code to clean them and store the records in a local table with indexing for better performance later. The local tables are emptied first with a delete query. The insert queries are logged with a data macro After Insert: LogEvent on the local table in USysApplicationLog. Data macro produces loads of records in USysApplicationLog, while 1 per table per insert would be sufficient for my cause. Open issue, but less important at this time.
The local tables have the same name as the linked table with the postfix "-local".
Examples: csvMachines / cvsMachines-local, csvCustomers / csvCustomers-local, etc.
At the moment I'm manually checking everything, doing all the queries, etc. But looking for a way to automate this more.
Before using the database with local tables I want to check if:
the local tables are up to date
got this kinda covered with querying the USysApplicationLog and UDF function to check modification date of sources
the local tables are filled
reason for my question here
Looking for a smart way (sql, vba or udf) to combine following working query
SELECT MSysObjects.NAME AS LinkedTableName
,[LinkedTableName] & "-local" AS LocalTableName
FROM MSysObjects
WHERE (((MSysObjects.DATABASE) IS NOT NULL));
with a simple SELECT count(*) per local table name.
Tried following but Access can't find LocalTableName as table.
SELECT MSysObjects.NAME AS LinkedTableName
,[LinkedTableName] & "-local" AS LocalTableName
,(
SELECT count(*)
FROM [LocalTableName]
) AS LocalTableRecordCount
FROM MSysObjects
WHERE (((MSysObjects.DATABASE) IS NOT NULL));
Looked at old similar questions as Create table - dynamic name of table and MS Access query with dynamic from statements, but didnt see how to implement their solutions in my situation.
Access will not let you provide a name for the FROM data source at runtime. It just does not support that capability.
Since you have a VBA tag on this question, perhaps you would consider a procedure which loops through your table names and retrieves the record count for each.
For each table name ...
strSelect = "SELECT Count(*) FROM " & LocalTableName
MsgBox CurrentDb.OpenRecordset(strSelect)(0)
Or look at the TableDef.RecordCount property ...
MsgBox CurrentDb.TableDefs(LocalTableName).RecordCount
Looking for a solution for another issue, I found an alternative anwser for this question in the Access Help: expression.DCount(Expr, Domain, Criteria)
Working query for my situation:
SELECT MSysObjects.NAME AS LinkedTableName
,[LinkedTableName] & "-local" AS LocalTableName
,DCount("*", [LinkedTableName] & "-local") AS LocalTableRecordCount
FROM MSysObjects
WHERE (((MSysObjects.DATABASE) IS NOT NULL));

sql or trick to search through whole database

is there a way to actually query the database in a such a way to search for a particular value in every table across the whole database ?
Something like a file search in Eclipse, it searches accross the whole worspace and project ?
Sorry about that .. its MS SQL 2005
SQL Workbench/J has a built in tool and command to do that.
It's JDBC based and should also work with SQL Server.
You will need to use the LIKE operator, and search through each field separately. i.e.
SELECT * FROM <table name>
WHERE (<field name1> LIKE '%<search value>%') OR
(<field name2> LIKE '%<search value>%') OR
... etc.
This isn't a quick way though.
I think the best way would be to
1) programatically generate the query and run it
2) use a GUI tool for the SQL server you are using which provides this functionality.
In mysql you can use union operator like
(SELECT * from table A where name = 'abc') UNION (SELECT * from
table B where middlename = 'pqr')
and so on
use full text search for efficency
http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
Well, your best bet is to write a procedure to do this. But to give you some pointers you can use the INFORMATION_SCHEMA.Tables to get a list of all the tables in a given database and INFORMATION_SCHEMA.Columns to get a list of all columns. These tables also give you the datatype of columns. So you will need a few loops on these tables to do the magic.
It should be mentioned most RDBMSs nowadays support these schemas.
In phpmyadmin, go to your database, reach the search tab.
Here you will be able to select all of your tables and search through your entire db in one time.

MS Access SQL DELETE - why would someone specify column names?

I'm having to support an Access .mdb file that someone else has written. One of the button functions in this .mdb calls out to delete some data in an external MSSQL database. All very straightforward, but this syntax isn't something I've seen before:
DELETE
tblEquipmentConnections.SourceEquip,
tblEquipmentConnections.EquipmentConnectionID
FROM tblEquipmentConnections
WHERE
tblEquipmentConnections.SourceEquip = [Forms]![frmEquipment]![EquipmentID];
Is that any different than this?
DELETE
FROM tblEquipmentConnections
WHERE
tblEquipmentConnections.SourceEquip = [Forms]![frmEquipment]![EquipmentID];
I can't find a case where specifying specific columns does anything - but I don't spend much time in Access, so I'm not sure how different the SQL syntax is...
Thanks!
Specifying the column names makes no difference. It's just an Access thing.
The reason they might be there is because Access used to generate DELETE statements that way (not sure if it still does).
The second form without columns names is obviously preferable.
I think the query has been built directly into Access query editor.
And generally we begin by building a select query. Then we change the query type from "Select query" to "Delete query". Then we display the query source by selecting "SQL Mode" where we copy / paste a sql statement like this one :
DELETE qc_Boxes.idBox, qc_Boxes.idScreen, qc_Boxes.title
FROM qc_Boxes;
This is absolutely redundant. The place between DELETE and FROM is used only when the deletion is performed based on a multi-table condition, but even in this case it contains table names and not field names. Also it can contain * which is also redundant. In MySQL, for example it's an incorrect syntax.