Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
deal11deal1
Starting Member
34 Posts |
Posted - 2011-02-11 : 12:37:43
|
| Hello all , I need to syncronize two tables in a same database. with a condition if the first table has row entry that already present in the destination table skip that one and enter the new 1's.I cant seem to figure out how to do it.the script i have so far is come thing like this.Insert data_userdataselect * FROM data_userdata_tmp AS tmpWhere tmp.userid not in (select userid from data_userdata As dmz)this script is working fine ... but the requirment has changed a bit now..in data_userdata_tmp if row that is already present in the data_userdata do not move that row in the destination table from the tmp table.Hope some one can help me on this. |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-11 : 13:59:07
|
| I think the where clause in your query is doing same work .. .it filters out all those rows which exists in the Data_UserData table and insert the ones that not exists |
 |
|
|
deal11deal1
Starting Member
34 Posts |
Posted - 2011-02-11 : 14:17:49
|
| Thanks for the response,thats what i thought too , but when i for testing reasons , create a entry in tmp table ,,,, where the row with the same email already present in the destination table i get the error .... it says ...."Description:cannot insert duplicate key row in objectdbo.data_userdata with unigue index "idxemail".now this unigue index ios there to prevent duplicate email in a table...i dont know how can I do this requirment.--- if the email is already present , dont write that record in the destination table. |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-11 : 14:28:32
|
well in this case its not the same record but two different user_IDs having same email address in the Temp table ... I think you have unique constraint on the email column which is not allowing you to insert a new ID (but with same email) into the destination. if it is not required an email to be unique for different user then you should remove the constraint OR on the other hand the data is not correct |
 |
|
|
deal11deal1
Starting Member
34 Posts |
Posted - 2011-02-11 : 14:35:19
|
| so , if i remove the cunigue constraint from the email col than it will enter same email 2 diffrent rows as long as the userid row is diffrent is diffrent? |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-11 : 14:39:55
|
as far as the query is concerned i believe it should, since the the filter is at UserID .. since you are testing then test this too hope it wont disappoint you .. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-02-11 : 16:11:18
|
quote: Originally posted by deal11deal1 so , if i remove the cunigue constraint from the email col than it will enter same email 2 diffrent rows as long as the userid row is diffrent is diffrent?
Is your requirement to allow more than one user to use the same email address? My guess would be no, but it's your database. |
 |
|
|
|
|
|
|
|