Following up on my earlier query , is there a way to specify the condition for the records that would be copied over using the column names on the same table? i.e. I want to copy all data from sandbox server to production server for all rows where COL_A in sandbox that do not exist in the production server. So the intended select query should be:
SELECT * FROM <Sandbox><TABLE_C> WHERE <Sandbox><TABLE_C>COL_A NOT EXISTS (SELECT <production>COL_A FROM <production>TABLE_C)
i.e. all the records from sandbox to production where a matching COL_A could not be found
I am not sure about Oracle specific syntax but something along these lines assuming that you are able to access them as linked servers -
INSERT INTO TABLE_C#prod_link
SELECT source.*
FROM TABLE_C source
LEFT JOIN TABLE_C#prod_link target
ON source.COL_A = target.COL_A
WHERE target.COL_A IS NULL
where prod_link is a database link
CREATE PUBLIC DATABASE LINK
prod_link
CONNECT TO
remote_username
IDENTIFIED BY
mypassword
USING 'tns_service_name';
I do not have an Oracle instance running that I can try this on but it should work
Related
I am new to using SQL Server from RStudio. I am connected to SQL Server from RStudio and the server has several different projects listed in the below image. For this work I am using odbc library. I am trying to retrieve the tables of a specific project(Project_3960). I have tried dbListTables(conn,"Project_3960") but this command retrieve the tables from all the projects listed in the below Picture. I just want to retrieve the table which are listed in dbo in Project_3690.
The first picture is from RStudio and the second picture is from SQL Management Studio to show the structure of the folders, in case for executing SQL Query.
Thanks
Click on the arrow to the left of the dbo object under Project_3690, and it should show you the tables you have access to. If it does not, then you have a permissions problem and will need to talk with the DBA. That allows you to see them via the GUI. In fact, if you don't already know the names of the tables you should be accessing (such as to follow my code below), then this is the easiest, as they are already filtering out the system and other tables that obscure what you need.
To see them in R code, then dbListTables(conn) will show you all tables, including the ones in the Connections pane I just described but also a lot of system and otherwise-internal tables that you don't need. On my SQL Server instance, it returns over 600 tables, so ... you may not want to do just that, but you can look for specific tables.
For example, if you know you should have tables Table_A and Table_B, then you could do
alltables <- dbListTables(conn)
grep("table_", alltables, value = TRUE, ignore.case = TRUE)
to see all of the table names with that string in its name.
If you do not see tables that you know you need to access, then it is likely that your connection code did not include the specific database, in which case you need something like:
conn <- dbConnect(odbc(), database="Project_3690", uid="...", pwd="...",
server="...", driver = "...")
(Most fields should already be in your connection code, don't use literal ... for your strings.)
One can use a system table to find the other tables:
DBI::dbGetQuery(conn, "select * from information_schema.tables where table_type = 'BASE TABLE' and table_schema = 'dbo'")
# TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE
# 1 Project_3690 dbo Table_A BASE TABLE
# 2 Project_3690 dbo Table_B BASE TABLE
# 3 Project_3690 dbo Table_C BASE TABLE
(Notional output but representative of what it should look like.)
Its not quite direct to retrieve the data from SQL server using RStudio when you have different schemas and all are connected to the server. It is easy to view the connected Databases with schema in SQL Server Management Studio but not in RStudio. The easiest way while using Rodbc is to use dot(.) operator and its easy to retrieve the tables of a specific data base is by using "." with dbGetQuery function. I tried dbGetQuery(conn, "select * from project_3690.dbo.AE_ISD ") and it works perfectly fine.
I'm developing a Rust application for user registration via SSH (like the one working for SDF).
I'm using the SQLite3 database as a backend to store the information about users.
I'm opening the database file (or creating it if it does not exist) but I don't know the approach for checking if the necessary tables with expected structure are present in the database.
I tried to use PRAGMA schema_version for versioning purposes, but this approach is unreliable.
I found that there are posts with answers that are heavily related to my question:
How to list the tables in a SQLite database file that was opened with ATTACH?
How do I retrieve all the tables from database? (Android, SQLite)
How do I check in SQLite whether a table exists?
I'm opening the database file (or creating it if it does not exist)
but I don't know the approach for checking if the necessary tables
I found querying sqlite_master to check for tables, indexes, triggers and views and for columns using PRAGMA table_info(the_table_name) to check for columns.
e.g. the following would allow you to get the core basic information and to then be able to process it with relative ease (just for tables for demonstration):-
SELECT name, sql FROM sqlite_master WHERE type = 'table' AND name LIKE 'my%';
with expected structure
PRAGMA table_info(mytable);
The first results in (for example) :-
Whilst the second results in (for mytable) :-
Note that type is blank/null for all columns as the SQL to create the table doesn't specify column types.
If you are using SQLite 3.16.0 or greater then you could use PRAGMA Functions (e.g. pragma_table_info(table_name)) rather than the two step approach need prior to 3.16.0.
I have a split Access 2010 database. Users have a copy of this database on their laptops and there is a main copy that resides on the I: drive server. Two tables exist for input on all copies: tblMedData and tblMyMedData. Users can perform a synchronization that moves the tblMyMedData data from their laptops into the tblMedData table on the I: drive server. tblMedData is then copied back to the tblMedData table on the laptop, so they have the latest data residing on their laptop.
The problem we're facing: if a change is made in the tblMedData table on the server, this change gets overwritten during the synchronization. During the synchronization, I've tried using a select query that checks for medications that exist in both the laptop tblMedData table and the server tblMedData table and if there are any differences between these records, but I can't figure out how to do this? Here's what I have so far:
SELECT tblMedData.* AS tblLaptopMeds, tblMedData.* AS tblServerMeds, tblMedData.Ratio,
tblMedData.Duration, tblMedData.Withdrawal, tblMedData.WaterOrInject, tblMedData.Deleted
FROM [C:\FolderName\DB.accdb].tblMedData AS tblLaptopMeds INNER JOIN
[I:\FolderName\Folder\DB_be.accdb].tblMedData AS tblServerMeds ON tblLaptopMeds.InvNo =
tblServerMeds.InvNo
WHERE (((tblLaptopMeds.Ratio)<>tblServerMeds!Ratio)) Or (((tblLaptopMeds.Duration)
<>tblServerMeds!Duration)) Or (((tblLaptopMeds.Withdrawal)<>tblServerMeds!Withdrawal))
Or (((tblLaptopMeds.WaterOrInject)<>tblServerMeds!WaterOrInject)) Or
(((tblLaptopMeds.Deleted)<>tblServerMeds!Deleted)) Or (((tblLaptopMeds.Ratio)
<>tblServerMeds!Ratio)) Or (((tblLaptopMeds.Duration)<>tblServerMeds!Duration)) Or
(((tblLaptopMeds.Withdrawal)<>tblServerMeds!Withdrawal)) Or
(((tblLaptopMeds.WaterOrInject)<>tblServerMeds!WaterOrInject)) Or
(((tblLaptopMeds.Deleted)<>tblServerMeds!Deleted)) OR
(((tblLaptopMeds.ChangedBy)<>tblServerMeds!ChangedBy));
Does anyone have suggestions? Am I making this too complicated?
Here is a snippet of searching for missing values:
select * from YourTable a
where a.YourIDField not in
(select b.YourIDFieldfrom YourTable b
where a.YourIDField= b.YourIDField)
I'm not sure if Not In will work in Access (esp if you're examining multiple fields), so try this if it doesn't:
select * from YourTable a
where a.YourIDField not exists
(select b.YourIDFieldfrom YourTable b
where a.YourIDField= b.Your
See this post for similar answer
I think if you look into what I posted along with Selecting from 2 databases on different servers you should be able to go figure it out fairly quickly.
I am trying to connect to a table that is not in the sys schema. The code below works if sys.tablea exists.
conn <- dbConnect(dbDriver("MonetDB"), "monetdb://localhost/demo")
frame <- monet.frame(conn,"tablea")
If I define tablea in a different schema, e.g. xyz.tablea, then I get the error message
Server says 'SELECT: no such table 'tablea'' [#NA]
The account used to connect has rights to the table.
In a related question, is it possible to use camel-case from MonetDB.R? When I change the table name to TableA, the server again responds with
Server says 'SELECT: no such table 'tablea'' [#NA]
where the table name is all lower-case.
Using tables in other schemata is not possible with the current constructor of monet.frame. However, you can work around the issue as follows:
frame <- monet.frame(conn,"select * from xyz.tablea")
This trick also works with CamelCased table names.
For the next version, I am planning to fix the issue.
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