Showing posts with label migrating. Show all posts
Showing posts with label migrating. Show all posts

Sunday, March 11, 2012

"ON DUPLICATE KEY UPDATE"?

Hi,

I am migrating from MySQL to SQL Express. In MySQL, I import data from Oracle using the "INSERT INTO .... ON DUPLICATE KEY UPDATE". With the "ON DUPLICATE KEY UPDATE", when there is a duplicate key in MySQL exists, the respective records will be updated (so to avoid inserting the data twice). I cannot remove the duplicated rows in MySQL as it contains extra fields with user-input value.

Is there any way I can do the same in SQL Express? Is it a must that I need to create a temp table to hold the downloaded data and then update the duplicated data in the original before an INSERT?

Thanks

Raymond

There is no equivalent functionality. You can however do the following:

1. You can create an unique index on the key column(s) with the IGNORE_DUP_KEY option set to on. This will result in the duplicate rows being ignored during the INSERT operation for instance. You will have to however update the rows by inserting into another table and then performing update

2. Use a worktable approach where you insert all the rows into the worktable and then use insert/update as into the main table.

|||

Thanks,

I think I will go for the second option, as there is only a few new records (inserts) every time, and most the other records involve changes (updates).

Raymond

Tuesday, March 6, 2012

"dynamical" view

Hi,

I'm currently migrating an MS Access database to SQL 2000 Standard, and i have a problem with queries migration.

In acccess, a screen allows me to view some informations depending on Criteria, and results are returned with a query (we'll call it Q1).

Then, when correct data are returned by the query Q1, some other queries compute sums, average, group by orders, based on Q1's results.

Now my question : as in sql server, a view cannot accept parameters, the solution i adopted is :

- create a generic Q1 view, not filtered.

- then, all the subqueries based on this view are Functions or Stored procedures, which accepts parameters and do the filter on the main view (Q1).

The problem is that writing such functions or stored procedures is quite long, and interface code has to be deeply modified to use these parameters.

First, I had the idea of creating a temporary table, in which i would have inserted the good data, an the other queries would have used it. Unfortunately, views can't use temporary tables.

Any good idea is expected. Thanks in advance,

So, i found a first way to do this, maybe not the best, but it seems to work correctly.

I generate the script to dynamically generate the view with the correct "where" statements.

The view's name is MyView_ + Host_Id().

It should work since we don't use a citrix server for client hosting...