postgresql list all table fields information within a server - sql

i'm in need to create VIEWS in postresql 9, to mimic oracle's col table,
basically it should display ALL table fields information from ALL table and ALL database on that server.
Can someone please point me a way? thanks.

Unlike Oracle, PostgreSQL implements the ANSI information_schema.
So Oracle's ALL_TAB_COLUMNS view corresponds to information_schema.columns
But this is only restricted to the current database. It is not possible to get this information for all databases - which is the same for Oracle, ALL_TAB_COLUMNS only shows the columns for the current database (=instance)
More details about the information_schema can be found in the manual
http://www.postgresql.org/docs/current/static/information-schema.html

I don't think is possible to get metadata information from a different database of that you've working right now.
To extract metadata from the current database, take a look here: http://www.alberton.info/postgresql_meta_info.html

Related

SQL query to pull all database table structure in one go?

I know this SQL query provides the table structure:
DESC TableName;
But do we have a query which will provide table structure of all database tables in one go/single query/command? BTW, I am using SQL Developer.
Thank you in advance.
The answer can be found here. You can query
SELECT * FROM ALL_TAB_COLUMNS
or
SELECT * FROM ALL_TAB_COLS
Difference between ALL_TAB_COLUMNS and ALL_TAB_COLS
Not a command, but if you're in the GUI, getting all that information back in a single query result set could be a challenge to process, at least for this human it is.
So instead, you could also build a Data Dictionary report, complete with Referential Integrity diagrams - not sure if your peoplesoft box will actually have any foreign keys, but it's worth a shot.
File > Data Modeler > Import > Data Dictionary
Point to your existing SQL Developer Oracle Database connection.
Select the SCHEMA you want to pull from - check all if you want everything, but be prepared to wait for awhile, better to limit yourself to the application schemas.
If you're just interested in tables, just pick those, but I'm guessing VIEWs would also be of interest - there's a checkbox on the bottom to quick toggle everything ON.
Click Finish.
When you're done, you'll have a design and your data model. You'll see the diagram.
You can then go to File > Data Modeler > Reports
Choose either the Tables or Table Views report.
Set your format, and click 'Generate Report'

I need to compare column structure of two tables in different databases but on the same instance in SQL Server 2016

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.

Describing Oracle Schema

I am having a huge Oracle database with multiple schema's in it.
i want to describe the entire schema (one schema at a time) with all the tabel's in that schema and the structure of those table i.e. column name , datatype.
how can i do this task using SqlDeveloper ?
Thanking in advance
Use Oracle's views:
all_tables,
all_tab_columns

Utility to create sql statements

This is a question about Sql generation, not sql creating sql nor ORM.
Is their any cross database tools that will enable the creation of insert statements, e.g. for all the tables in particular schema or namespace. Say the namespace/schema is Aqua in Sql Server 2008, and your utility comes along and generates all possible insert statements for that namespace/schema. And it works on Oracle/MySql/Postgres/db2 etc.
Thanks.
Bob
ANSI SQL provides for a standard set of views under the schema INFORMATION_SCHEMA to provide metadata for just this purpose.
For generating simple table insert statement templates, all the information you really need to generate an insert statement for a given table is to execute this query:
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_CATALOG = <my-db-name>
and TABLE_SCHEMA = <table-owner-schema>
and TABLE_NAME = <table-name>
order by ORDINAL_POSITION
in any database that supports the ANSI information schema views. That will give you one row for every column in the specified table, in the expected sequence.
Outside of the above, since no two vendors support the set of system tables with metadata, your pretty much SOL for a cross-database solution. And sadly, I don't believe the Oracle supports the ANSI information schema views.
Though you might look at Red Gate's product family: http://www.red-gate.com/

Listing all tables in a database

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