I'm connecting to a Caché database using the ODBC driver, and I want to do a query to obtain a list of schemas. In Microsoft SQL Server I can use a query like this:
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
How can I do this in Caché? I'm also using ADO.NET schema collections, but the schemas don't seem to be available there.
The schema %dictionary has the tables you are looking for. You could select from %dictionary.compiledclass
Related
I have an sql linked server whose data I can access using openquery, but I have no idea of how to see the tables of that database, hence i cant do much.
I only have a query
SELECT * FROM OPENQUERY(MYSERVER, 'SELECT * FROM SERVXML.DATA AS A WHERE A.DATAID = 2355')
Which returns some stuff.
But otherwise how can I see all the info in MYSERVER? I mean all the tables more specifically.
I have tried using this
EXEC sp_tables_ex 'MYSERVER';
With no result.
I'm a little confused. If you have a linked server, then you can just access the tables using a four-part naming convention: ...table.
This is explained in the documentation.
You can see the linked servers using metadata tables and views. For instance:
select *
from <server>.<database>.INFORMATION_SCHEMA.TABLES
I need to compare column structure of two tables in different databases but on the same instance in SQL Server 2016!
Use System Information Schema Views. This should get you started:
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
Use this query to get information of column structure in a database and compare against another db
use DB
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='YourTableName'
This is external software, but unless you have Visual Studio premium where the functionality is built in, you can use something like Red Gate Schema Compare as a trial version to compare and generate a script to synchronise your tables, stored procedures etc.
I have a local (read and write) sqlite database and a remote (read-only) oracle database. I use ODBC to access both DBs (I use an application to access the DBs by ODBC and query as such: EXECUTE-QUERY SQLITE "SELECT ..." or EXECUTE-QUERY ORACLE "SELECT ...") . I tried searching the net for a way to be able to perform one query joining tables from the 2 databases, but all I find is how to create a database link from oracle to other DBs but that doesn't help me because I have no write priviledges for the Orcale DB so creations of database links, databases, tables, views are not allowed in ORACLE, all I can do is query there. Is there an efficient way to do this with the restraints that I have?
How big are the tables in oracle? Given the limits of the access you have and the technology you are working with ( sqlite and oracle are worlds apart ), your best bet would probably be to export the tables from oracle into sqlite, then do your queries all within that.
Finally I installed Oracle express edition and created a database link to the other (read-only) oracle database. That worked great.
Is there a SQL command that will list all the tables in a database and which is provider independent (works on MSSQLServer, Oracle, MySQL)?
The closest option is to query the INFORMATION_SCHEMA for tables.
SELECT *
FROM INFORMATION_SCHEMA.Tables
WHERE table_schema = 'mydatabase';
The INFORMATION_SCHEMA is part of standard SQL, but not all vendors support it. As far as I know, the only RDBMS vendors that support it are:
MySQL
PostgreSQL
Microsoft SQL Server 2000/2005/2008
Some brands of database, e.g. Oracle, IBM DB2, Firebird, Derby, etc. have similar "catalog" views that give you an interface where you can query metadata on the system. But the names of the views, the columns they contain, and their relationships don't match the ANSI SQL standard for INFORMATION_SCHEMA. In other words, similar information is available, but the query you would use to get that information is different.
(footnote: the catalog views in IBM DB2 UDB for System i are different from the catalog views in IBM DB2 UDB for Windows/*NIX -- so much for the Universal in UDB!)
Some other brands (e.g. SQLite) don't offer any queriable interface for metadata at all.
No. They all love doing it their own little way.
No, the SQL standard does not constrain where the table names are listed (if at all), so you'll have to perform different statements (typically SELECT statements on specially named tables) depending on the SQL engine you're dealing with.
If you are OK with using a non-SQL approach and you have an ODBC driver for the database and it implements the SQLTables entry-point, you possibly might get the information you want!
pjjH
details on the API at:
http://msdn.microsoft.com/en-us/library/ms711831.aspx
is there a way to create a select statement that would retrieve data from multiple database in postgre?
i was thinking it would be something like this:
select * from dbname1.table1, dbname2.table2 where dbname1.table1.column1 = dbname2.table2.column1
Have a look at the "dblink" contrib module.
OTOH it's possible that you treat the databases in a PostgreSQL cluster as equivalent to the databases in... let's say MySQL. Which is incorrect - the PostgreSQL databases contain schemas and those are the equivalent of the databases in MySQL.
From here:
It is not possible to access more than
one database per connection.
Update: but see Milen's answer.