I am copying data from MS Access to SQL Server using SSIS. Only one time I am gonna copy, it is not repeated task.
There is only one source table(Table_Source).
I want to insert data into two tables (Table1 and Table2).
Table1 contains a primary key which is a identity column.
After inserting into table1, I need to get the identity value of the row and
insert it as foreign key in table2 with some values from Table_Source.
Example:
Table_Source(EmployeeNo,LocationName)
Table1(ID,EmployeeNo)
Location(ID,LocationName) reference table
Table2(ID(FK to Table1),LocationID(FK to Location)
How to achieve this thro SSIS?
Thanks in advance.
Bhaskar
You'll find the information you need in this question: SSIS Data Transformation
Related
Here is the screenshot of the Parts table
INSERT INTO Supplies(Cost)
VALUES(10.0);
INSERT INTO Supplies(Cost)
VALUES (20.0);
INSERT INTO Supplies(Cost)
VALUES (30.0);
SELECT * FROM supplies;
Here is the Supplier table
Hello Everyone,
I am working on creating a database (three tables) in MySQL and every time I run an insert statement to input a record into my Supplies table, it says 'Field Supplier_SupplierID' doesn't have a default value'. When I created my model in MySQL, I already auto-incremented 'Parts_PartID' column and that error doesn't exist anymore. So why is it doing it with 'Supplier_SupplierID' column now? Can someone please help me? Here is my model pic and sample of SQL code when I insert records into the Supplies table.
You cannot insert into Supplies without providing the foreign keys for the Parts table and Suppliers table. While those primary keys in those tables may be incrementing automatically, they need to be already known when inserting into Supplies.
Typically you will use the known PartID and SupplierID that have previously been created when inserting into the Supplies table. Those columns cannot be NULL (by definition of your table).
'Field Supplier_SupplierID' doesn't have a default value' means that you are not providing a value, there is no default value and it's not allowed to be NULL.
I'm working with phpmyadmin and I have to merge two db with same structure but different data.
The db have relation between tables (foreign key).
The data in two db may have same id, and so their foreign key.
I would like to know if it's possible merge the two db keeping all data, so, if a row already "exist", insert it with new id and update its foreign key.
thanks a lot
No easy way unfortunately. If you have TableA as a foreign key to TableB, you will need to
1) Insert data from source tableA to target tableA
2) create a (temp) table to store the mapping between source tableA ids and target tableA ids
3) Use this mapping table when inserting data from tableB to convert the tableA ids to the new ones in the target db
... and so on. It can get quite hairy if you have a deep hierarchy of tables, but hopefully you get the idea. Take backups before you start.
Another idea that you might want to consider is using a cursor:
Assume table A is the one that you want to keep and table B is the one you want to remove.
Declare a cursor for table B and select all the records.
Loop each record selected from the cursor and check.
Case 1: If the ID is exists on table A, insert the record to table A with same details.
Case 2: If the ID is exists on table B, insert the record and modify the ID and foreign key.
Once all the records have been checked, drop table B.
Sorry, I just can give an idea at the moment.
I'm having a sql task which insert a single row record into table A each time.
Following by a data flow task which read all of the records from a csv file and save it into table B.
My question - How do I get the primary key that inserted into table A and insert it into table B ?
*Can It be done by insert the records from csv and also the primary key from table A at the same time ?
If you can select from table A last inserted record (PrimaryKey). You can use in dataflow lookup element and in lookup element write query which gonna select your wanted PrimaryKey.
I have two tables in one database
customer table have customer coordinate infos
Customer type have infos about the type of customer
I want to have a destination table that has
destination customer table
key
name
adress
...
type
I did create a database vue of customer table + customer type but the result query only showed me the fields that have customer table key=customer table foreign key in customer type
and there are also fields in customer table that have no type.
How do I solve this issue
What kind of transformations did you use in your data flow task?
I rather do it on the SQL Server using INNER JOIN and something like SELECT INTO. If you want to join two tables on SSIS, use the Merge Join Transformation. However, the input for the Merge Join Transformation must be sorted so you can either use the Sort Transformation or just use ORDER BY when you get the data using OLE DB Source adaptors.
Hope this helps.
I need to run a application to collect the news feeds and update new entries in my database. So I planned to create two tables one source and other as target.
My plan is to first update all the information into source table and latter update target table with unique data (currently updated news or new records).
But the issue is some feeds are repeated in some other websites. so the application breaks immediately after reading a duplicate entry.
I have attached my MySQL query below
create table table1 (
DateandTime datetime,
Name tinytext,
Title varchar(255),
Content Longtext unique(Title)
);
I know that this sounds too basic. But i dont have any solution.
I appreciate your feedbacks and Ideas. Thank you
Few solutions:
Unique column should prevent duplicate data
INSERT WHERE NOT EXISTS
Use MERGE engine in MySQL (http://dev.mysql.com/doc/refman/5.1/en/merge-storage-engine.html)
I modified my query on Marcus Adams suggestion.
Insert Ignore table1 (
DateandTime,
Name,
Title,
Content)
values
(.......
);
I think single table is sufficient to address my issue.Thank you