PostgreSQL compare data across different servers [duplicate] - sql

This question already has answers here:
Possible to perform cross-database queries with PostgreSQL?
(9 answers)
PostgreSQL cross server query? [closed]
(2 answers)
Closed 9 years ago.
I've one problem regarding manage information from two different Postgres servers.
In the one server I've one table a containing id bigserial and phone varchar(200)
On the other server I've table b that contains id bigserial and tell varchar(200)
Is there a way that I can compare witch rows from table a are present in the rows of table b, comparing by phone = tell?

You can use dblink to fetch data from remote server. Once you have a cursor open you can treat data from dblink_fetch as data returned from local table and just outer join it with the local table. If there are many rows in the remote table you might want to use pl/pgSQL to fetch it in parts.

Related

MS Access UPSERT (Update/Insert) SQL [duplicate]

This question already has answers here:
Upserting in MS-access
(6 answers)
Closed 6 years ago.
I know this question must have been asked a million times but I have yet to find a "NON-VBA" solution to this in MS Access 2007 SQL.
I am using 2 Tables TBLDestination and TBLSource. I have to update the destination table records from source table records when a matching ID is found. For a non-matching ID (i.e. new ID) I want to insert the new record
(Please refer the tables below).
-----TBLSource-------
ID (match if ID exists in Destination table)
EmpName
EmpAdd
---TBLDestination-----
ID
EmpName (to be updated/inserted)
EmpAdd (to be updated/inserted)
Salary
Access DOES have the equivalent using an UPDATE with a LEFT JOIN. See here.
MS Access doesn't have an equivalent to UPSERT where you can do both in a single query.
However, you can get the same effect by doing an UPDATE query where you join to the table you want to update from. Then you do an INSERT query where you OUTER JOIN to the table and return only those where it doesn't exist.

Filtering a SELECT statement based on row data [duplicate]

This question already has answers here:
Query to list number of records in each table in a database
(23 answers)
Closed 7 years ago.
I'm trying to add a WHERE clause to a SELECT statement that checks to see if there is data in the table or if it was a 0-row table.
Basically, I'm trying to get this to work but obviously tables.NAME isn't a valid object.
SELECT NAME
FROM sys.tables
WHERE (SELECT Count(*)
FROM tables.NAME) <> 0
I don't want to have to create a temp table, declare a cursor and checking a value row by row, but I'm having a hard time thinking a bout how to do this otherwise.
Using a cursor is a suitable solution to this problem. You can't dynamically interpret a column from one table as a table name and simultaneously select from that table to see if it's empty like you're attempting to do. In fact you can't even select from a dynamic table without using dynamic SQL. See the documentation for FROM. You can either iterate over each table and check each, or you can query system tables that hold storage statistics to see if tables are empty.

Get row count of all tables in database: SQL Server [duplicate]

This question already has answers here:
Query to list number of records in each table in a database
(23 answers)
Closed 8 years ago.
I'm trying to familiarize myself with a large database and search for relevant information among the many tables. I often find myself calling up a table, to see if there is relevant data inside, only to find that the table has no records.
How to quickly call up a list of all tables and the number of records contained therein? I'm using sql server 2008.
Thanks!
Related Question: How do I QUICKLY check many sql database tables and views to see if they are not empty or contain records
Right click on database -> Reports -> Standard Reports -> Disk usage by Top Tables
If you want to use a query, you can use this (note: it's using an undocumented stored procedure sp_msforeachtable):
create table #tempcount (tablename nvarchar(128), record_count bigint)
EXEC sp_msforeachtable 'insert #tempcount select ''?'', count(*) from ? with (nolock)'
select * from #tempcount
drop table #tempcount

Select a row/column that has a data of 'dataname' [duplicate]

This question already has answers here:
Find a value anywhere in a database
(18 answers)
Closed 10 years ago.
is there a select query where I can find a column that has a data named 'Hello'. I'm not looking for a data on a single table, but am looking for a data on a whole database.
#aedz: here are some suggenstions/hints for you, basically this is easy to google:
MSSQL:
SQL Server: Search all tables for a particular GUID
http://gallery.technet.microsoft.com/scriptcenter/c0c57332-8624-48c0-b4c3-5b31fe641c58
http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm
Search for a string in all tables, rows and columns of a DB
http://justgeeks.blogspot.de/2006/10/search-ms-sql-server-for-any-text.html
http://www.sqlservercentral.com/Forums/Topic419243-8-1.aspx
http://www.mssqltips.com/sqlservertip/1522/searching-and-finding-a-string-value-in-all-columns-in-a-sql-server-table/
http://www.mssqltips.com/sqlservertip/1555/sql-server-find-and-replace-values-in-all-tables-and-all-text-columns/
MySql:
Search for all occurrences of a string in a mysql database
Search in all fields from every table of a MySQL database
MySQL tool that searches for a string in all fields, tables and databases
mySQL query to search all tables within a database for a string?
http://kedar.nitty-witty.com/blog/search-through-all-databases-tables-columns-in-mysql

Insert into two tables in one statement SQL SERVER 2008 [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
SQL Server: Is it possible to insert into two tables at the same time?
Select from one table and insert to another two table
I have two tables with one-to-one relationship
according to the result of a select statement I need to insert the resultant values in those tables
I really need to avoid cursors, do you know how I could insert in both tables with one select statement , or do you know some other solution that is better in performance, the table I'm querying is expected to get really huge and looping through it would be bad
thanks in advance