Restore parts of Postgres database dump - postgresql-9.1

I have two databases, db1 and db2. They're not identical but do share some tables, t1, t2 and t3.
I have dumped d1 to dump1.sql, and now I want to restore t1, t2 and t3 of that dump to d2. What would be the best way for me to do this?

Related

Kusto join tables from different DB

I have a requirement to join 2 tables in Kusto but they are in different Database under same cluster.
I can see the below Query works if the tables are in Same DB.
Table1 | join (Table2) on CommonColumn, $left.Col1 == $right.Col2
But could you please tell me how do I join 2 tables in diff DB.
for example
DB1 - Table 1 - This is where I run the Query
DB2 - Table 2 - this is where I would like to take a join and I have the common column name - RunID
If you're running the query in the context of db1, then you can run a cross-db query like this:
Table1 // assuming Table1 is in db1
| join (database("db2").Table2) on CommonColumn, $left.Col1 == $right.Col2
If you don't know (or don't want to rely) on the database in the context of which the query runs, you can prefix all the tables with the relevant database name, like this:
database("db1").Table1
| join (database("db2").Table2) on CommonColumn, $left.Col1 == $right.Col2
I was able to take the join with the below query
| join kind = innerunique (
database("DB2").Table2) on $left.RunID == $right.RunID
Thanks

How can I merge many SQLite databases into a file or database?

I have multiples databases with the same table name. Is there any SQL command or API to merge multiple databases.
lets assume to perform a join between a table that is in database A, to a table that is in database B
SELECT *
FROM A.table1 t1 JOIN B.table2 t2 ON t2.column2 = t1.column1;
cheers

How can I create the virtual table using FTS in SQLite

How can I create the virtual table using FTS in SQLite.
I have 3 tables, but I don't want to add the columns manually into the table.
For example: I have the 3 tables
like: t1(t1_id,t1_name), t2(t2_id,t2_name), t3(t3_id,t1_id,t2_id,t3_name)
Now, I want to create virtual table in which I want to give only t3 and
the columns in t1 and t2 should automatically map into the virtual table.
The expected output should be:-
virtualTable(vt1,t3_id,t3_name,t2_id,t2_name,t1_id,t1_name)
I refer this and this links, but I didn't find the solution for my question

SQLite how to delete all connected rows from other tables?

i have the following problem. I have three tables, TABLE_1, TABLE_2 and TABLE_3.
Between TABLE_1 and TABLE_2 is a m:n relationship so theres a connecting table
lets call it TABLE_1_2.
Between TABLE_2 and TABLE_3 is a m:n relationship so theres a connecting table
lets call it TABLE_2_3.
If i delete now a row from TABLE_1 i want that all rows from the other tables connecte also will be deleted.
How can i handle this? i read that sqlite doesnt supports joins for delete statements.
In MS SQL this can be made via altering the table1 and corresponding column by adding ON DELETE CASCADE CONSTRAINT on this column. But in SQLite there is no ALTER COLUMN and ALTER TABLE is also much less functional than in MS SQL. That's why you'll probably have to
Rename the table1 to a table3
Create a new table with ON DELETE CASCADE CONSTRAINT and all other constraints you've already used.
Copy the content of the old table to the new one.
Remove the old table
See also the similar topic.

Can I retrieve Data from two Databases?

I want to retrieve some data to use it in my grid, but the problem is my database design contains two databases.
So, can I retrieve data from more than database, to use it at one grid ?
I use ASP.Net, C#.Net 4, Microsoft SQL Server 2008 R2
SQL Server knows 4 part object names. The first part is the (linked) server name. The second part is the database name. third and fourth are schema and object name.
Assuming your databases are on the same server you can just write a query like:
SELECT *
FROM Database1.dbo.Table1 t1
JOIN Database2.dbo.Table2 t2
ON t1.column = t2.column;
There are several ways depending on your architecture.
If your databases are deployed in the same machine you can select data from two different databases like this:
SELECT a.userID, b.usersFirstName, b.usersLastName
FROM databaseA.dbo.TableA a
inner join database B.dbo.TableB b ON a.userID=b.userID
Of course you should have permission in both databases.
You can check here for more information: http://forums.asp.net/t/1254974.aspx/1

Resources