Transfer data from one database to another database with different schema - sql-server

i have problem to Transfer data from one sqlserver 2008 r2 to another sql server 2012 databases with different schema, here is some different scenario,
database 1
database 1 with tables Firm and Client, these both have FirmId and ClientId primary key as int datatype,
FirmId is int datatype as reference key used in Client table.
database 2
database 2 with same tables Firm and Client, these both have FirmId and ClientId but primary key as uniqueidentifier,
FirmId is uniqueidentifier datatype as reference key used in Client table.
problem
the problem is not to copy data from 1 database table to 2 database table, but the problem is to maintain the reference key's Firm table into Client table. because there is datatype change.
i am using sql server 2008 r2 and sql server 2012
please help me to resolve / find the solution, i really appreciate your valuable time and effort. thanks

I'll take a stab at it even if I am far from an expert on SQLServer - here is a general procedure (you will have to repeat it for all tables where you have to replace INT with UID, of course...).
I will use Table A to refer to the parent (Firm, if I understand your example clearly) and Table B to refer to the child (Client, I believe).
Delete the relations pointing to Table A
Remove the identity from the id column of Table A
Create a new column with Uniqueidentifier on Table A
Generate values for the Uniqueidentifier column
Add the new Uniqueidentifier column in all the child tables (Table B)
Use the OLD id column to map your child record & update the new Uniqueidentifier value from your parent table.
Drop all the id columns
Recreate the relations
Having said that, I just want to add a warning to you: converting to UID is, according to some, a very bad idea. But if you really need to do that, you can script (and test) the above mentioned procedure.

Related

Inserting Records into ASE linked table results in single-row update/delete affected more than one row of a linked table

In Microsoft Access 2016 i have a link to an ASE table trough the Adaptative Server Enterprise ODBC driver.
The table is used only has a data pass table for database admins
On the server side the table has no indexes, primary keys or foreign keys
When linking the table in access, it always asks you to identify the primary key/keys in order to be able to insert records into it.
In Microsoft Access 2010 they had it working by identifying 10 fields as primary keys just so that records could be inserted from access
In Micrososft Access 2016 i am getting the error:
Single-row update/delete affected more than one row of a linked table.
Unique index contains duplicate values. (Error 3362)
Is there a way to allow access to insert records into this table without declaring a primary key, since the server table has none?
Thanks in advance

SSIS designer Visual Studio foreign keys integration

I need to integrate two similar databases into third DB3. DB3 is almost the same as DB1.
First database DB1:
Addresses table with: primary key AddressId
People table with: primary key PersonId , foreign key AddressId
Second database DB2:
It is pretty similar, but in other language
Data from DB1 to DB3 flows smoothly, table after table. For example I have 1000 records in DB3 table named Addresses from DB1 and 1000 records in table named People from DB1.
Let's suppose Person with number 30 in DB3 (after transfering from DB1) has the IdAddress number 20.
Address with number 40 in DB2 has the ID number 1040 in DB3 and the Person has ID number 30 in DB2 and 1030 in DB3.
While transferring table People from B2 to B3 we need to know the address ID is not 40 but 1040.
I'm trying to use lookup to find existing record, but I'm newbie in SSIS VS designer. Could you help me? How can I resolve this problem?
Suggestions
You can do this using Lookup Transformation component as you mentioned, but first you have to:
Select the basic information of each table that can distinguish each logical entity. Example if talking about Persons you can choose the Fullname+ Mothername + Date Of Birth , ...
After selecting this attributes you have to add a Lookup Transformation
Map thiese columns between Source and Lookup table
Select the ID column (from Lookup table) as Output and rename the column to be NewID
Select Ignore failure option to handle non matches situation
After doing these steps, if the same person was inserted previously you will get the ID in NewID column, else NewID is NULL
Additional Information
Microsoft Docs - Lookup Transformation
UNDERSTAND SSIS LOOKUP TRANSFORMATION WITH AN EXAMPLE STEP BY STEP
SSIS Lookup Transformation
Lookup Transformation in SSIS

Identity column in a budget table

Programming noob here, and DBA I am not..
I am creating a table called 'budget' on a 2005 sqlserver databases. The purpose of this table is to simply store the monthly $ allowed to departments for budgeting purposes.
The essential columns in this table will be month, year, dept, amount. I am migrating this from an old foxpro table which did not have an identity/primary key column.
My question is, for my purposes do I need to worry about creating an identity column? I am having a hard time importing the data into SQLserver and having it populate the ID column, so I am inclined to just skip it if it's not needed. Thanks for your $.02
If you're specifying a PK in your insert statement, you'll need to use SET IDENTITY_INSERT <tableName> ON at the beginning of your query.
For more information, look here.

Sequences in Oracle to Identity columns in SQL Server

I need to 'migrate' a table in Oracle, this table has a primary key column with a sequence and a trigger to autoincrement this column mentioned, the process is detailed here.
The question is, I want to migrate this table to SQL Server put I want to take advantage of the identity feature. How can I tweak the table in SQL Server? Taking in count the fact I need to migrate the data and I don't want problems with the autoincrement column; will I lost the previous id assignation in Oracle?
No, you create the table with an identity column, like
MyID int identity([your max ID],1)
then when you insert the oracle data, prior to the insert run this command
SET IDENTITY_INSERT MYTABLE ON
/*insert your records*/
SET IDENTITY_INSERT MYTABLE OFF

SQL server 2005 :Updating one record from 2 identical records

I have 2 records in a table in SQL Server 2005 db which has exactly same data.
I want to update one record.Is there anyway to do it?Unfortunately this table does not have an identity column and i cant use a direct update query because both will be updated since data is same.Is there anyway using rowid or something in SQL server 2005 ?
I don't much like the TOP operator, but:
UPDATE top (1) MyTable
set Data = '123'
where Data = 'def'
Really, you want to have primary keys on your tables to avoid just this kind of situation, even if they are just identity surrogate values.
I would add an identity column to the table and then update on that identity column or update based on whatever the primary key of the table is that makes the row unique.

Resources