Will updating ID column manually harm the database? - database

My question is exactly as described above
My case is:
I need to migrate old server data to a new server
I have extracted all the required data on excel sheets
Example of an entry of an article
id 200
title whatever
linked_item_id 1400
Many deletion occured as filtering to the old data so it's not starting from 1 anymore
That's why when i import this data on the new server, I'll need the article to have ID 200 and the linked item to be 1400 so i can associate it on the new system using xlsx importer with a custom methods
After that, normal and proper usage for the DB should be happening through the app (This is to import the data only)
3 Questions here which i need the answer for:
1- I just want to make sure that updating the ID after saving the record won't harm the DB, will it ?
2- Will that affect the performance of loading the relations ?, as the foreign_keys isn't entered properly
3- Assuming i have newly initiated DB and i added first record and it got ID 1, then i manually updated the record to be ID 200
Will the next record take 201 or 2 ?
Thanks in advance

Related

Duplicate Entries when updating the DB

My question is as follows, when using postgresql or mongodb if i have new data flowing into the DB can it handle duplicates?
Going more into the details the data is dynamic for example product AAA price 100$ type package, after the initial creation future updates of the data can contain old entries so there is a duplicates issue and also some fields of the older entries might be updated so what i want is only to get the updated data without creating duplicate entries so if the price changes on the older entries that gets updated and if there are newer entries they get inserted.
Is it possible on the DB level or am i asking for too much?

Creating relationship Neo4J during import if value is 1

Hello all you helpful folks!
I have been tasked with converting our RDBM into a Graph database for testing purposes. I am using Neo4J and have been successful on importing various tables into their appropriate nodes. However, I have run into a slight hiccup when it comes to the department node. Certain department are partnered with a particular department. Within the RDBMS model, this is simple a column named: Is_Partner because this database was originally set up with one partner in mind (Hence the whole: Moving to a Graph database thing).
What I need to do is match all department with the Is_Partner value of 1 and assign a relationship to from the partner who has the value of 1 in Is_Partner and assign it to a specific partner (Edge: ABBR, Value: HR). I have written the script, but it tells me it's successful, but 0 edits are made...
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///Department.csv" AS row
MATCH (partner:Department {DepartmentID: row.DepartmentID})
WHERE row.IS_PARTNER = "1"
MERGE (partner)-[:IS_PARTNER_OF]->(Department{ABBR: 'HR'});
I'm pretty new to Graph Databases, but I know Relational Databases quite well. Any help would be appreciated.
Thank you for your time,
Jim Perry
There are a few problems with your query. If you want to filter on CSV use WITH statement with a WHERE filter. Also you want to MERGE HR department node separately and then MERGE relationship separately.
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///Department.csv" AS row
WITH row WHERE row.IS_PARTNER = "1"
MATCH (partner:Department {DepartmentID: row.DepartmentID})
MERGE (dept:Department{ABBR: 'HR'}))
MERGE (partner)-[:IS_PARTNER_OF]->(dept);
If it still return no results/changes, check out if your MATCH statement return anything as this is usually the problem.
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///Department.csv" AS row
WITH row WHERE row.IS_PARTNER = "1"
MATCH (partner:Department {DepartmentID: row.DepartmentID})
RETURN partner

How to import only the NEW records during Excel-import from SQL

I am currently receiving a push-feed with data into a SQL Server Express database. The feed is updated randomly several times a minute (pushed into the database). I want to import the new updated records into Excel by making a call every three seconds from Excel to the SQL Server database.
I discovered that there are three methods to import the data from SQL Server into Excel:
https://www.excel-sql-server.com/excel-sql-server-import-export-using-vba.htm
import using QueryTable
import using ADO
import using Add-In
Although with these methods the complete table is imported from the database every time. I only want to import the new added records since the last import since the SQL Server database becomes very large.
I have two questions:
1) How can I import only the new added records?
2) What is the most efficient method regarding speed and system-load from the above three import methods?
Thank you!
I do not think it is correct to say Import to Excel. More correctly would be to say Export from SQL Server to Excel.
There can be few ways to do this. Will rate them from easiest/fastest to complicated/slowest:
Easiest one: You add a new column to your SQL table as a "Exported flag" and mark it for all exported columns. So, next time you will be able to export the newest records where value in that column is empty. That column can have type "BIT", "TINYINT" or even "DATETIME" to indicate when that record was exported. The problem with that method only in the case when you are not allowed to add any new columns to the table. Here is sample code to Update flag and extract values in one transaction:
UPDATE #tbl_TMP
SET Flag = 1
OUTPUT DELETED.A, DELETED.B, DELETED.C
WHERE Flag = 0
If you are not allowed to add new column you might use existing columns in the table. For instance if you have any Time stamp or Incremental value in the table you can record the latest extracted value and all records bigger than stored value will be "newest records to extract".
If table does not have Time stamp or Incremental values you can
create another table, which will contain list of already extracted
key values from the table. Then by linking these tables you can
figure out which records are new.
If table does not have key value you can store HASH of all or several columns in another table and then link by that HASH to figure out the new ones.
Create a linked server to the Excel data.
Put an INSERT trigger on the SQL Server table to insert all new rows to the spreadsheet

Preventing 'The data has been changed' error when using Me.Refresh with ODBC linked tables

In my Access application's data entry form I'm using Me.Refresh to show the user the new value of a calculated field based on data they entered in a non-calculated field. The purpose is to give them the deadline for doing a job next.
This Access app is using linked SQL Server 2012 tables via ODBC. The calculated field is in the underlying SQL Server table, not part of the Access Record Source query because I want to store the calculated value in the actual data, not just as an interface element.
The calculation is very simple:
nextjob = jobdate + 79
So I have the field for jobdate set to run Me.Refresh after update. All well and good.
The problem is that if the user updates jobdate, triggers the refresh by moving to another field, then returns to the jobdate field and changes the date they entered Access throws a "The data has been changed by another user" error.
I tested the method using native Access tables and the problem does not occur. However the data needs to stay on the server, so moving to native tables is not a solution for me.
There are several possible solutions.
1- If it's always jobdate + 79, don't store it at all, use a view that has the calculated field.
2- Use Me.Requery instead of Me.Refresh. If the form shows multiple records, you must navigate back to the current record, you can use Me.Bookmark for that.
3- Move the calculation into the Access frontend - make nextjob an ordinary column and set it in the form, so it isn't another user (the server) that updates the data.

Adding only new records to my database

I am trying to access a SQLite database (that basically reads info about phones connected to network) , retrieve info and store them into my domain variable's to be stored in the webservice (that view the only of connected phone) database. The thing is I retrieve all the info every 5 secs, and want to add to my database the new records only(new connected phones). what is the proper method to do that?
There is two approach that I could think of:
1.Have a variable that saves the last rows id and every time you want to retrieve data from your database, just read data with bigger id than what you have in your variable.(this could only work if your id is incremental)
2.Add another boolean column to your database and make it true when you read that row, and every time you read from database just query rows which that column in them are false.
I personally prefer the first approach.

Resources