Sunday, September 29, 2013

[SQL Server 2008 issues] synch two tables

[SQL Server 2008 issues] synch two tables


synch two tables

Posted: 28 Sep 2013 05:04 PM PDT

Guys,I have two tables one is users and the other is frap_users ,Both contains some common attributes which are required to be same means if there is any change in the users table the same column has to updated in the frap_users and vice versa and this has to done through triggers only.When i have written triggers it is getting into infinite loop.I will appreciate any thoughts and suggestions on this.Am using Sql server 2008Regards,Papis

Need Help on Fastest Search Logic

Posted: 27 Sep 2013 11:19 PM PDT

Hi,I have two tables named "Table1" and "Table2".Table1 Details:id bigint, product_name nvarchar(1000),quantity intrecords count on Table1 : 25000( may increase in future)Table2 Details:id bigint, product_name nvarchar(max),details nvarchar(1000), description nvarchar(1000)Note: Table2 productName column will have comma separated valuesrecords count on Table2 : 186289( may increase in future)sample data: Table1:1 canola 1202 bread 1303 sauce 1404 corn 120Table2:1 canola,tea,muffin,cheese jellyproducts null2 vinegar,canola,sunflower oliproducts null3. cornil,vegoil,canola,sesameoil oilproducts nullmy requirement is i will take each prodcutname from Table1 and will search it in Table2's prodcutname column. if matches found then get the row and insert into temp table.i tried with while loop/cursor with "like" condition but it takes 15+ hours to process the records. I know searching in comma separate data with "like" will take time, but it take 15+ hours and still running. if am not wrong that looping will be bad on this larger records. so i have tried with joins as well. but nothing seems reducing the processing time.[code="sql"]Try1 : select T2.* from dbo.Table1 t1inner join dbo.Table2 t2 on t2.product_name like '%' + t1.product_name + '%' Try2: select T2.* from dbo.Table2 T2inner join dbo.Table1 T1 on CHARINDEX(T1.product_name, T2.product_name) > 0 [/code]Is there any fastest way to achieve this requirement? please help me on this and share with me sample code if there is any.

No comments:

Post a Comment

Search This Blog