How can i update bulk data in sql server 2005 by sending the data in XML form ? i am able to insert bulk data into the table, but i am not getting idea to update the data.
Insert into #TempTable
//Basically do bulk insert into temp table then...
Update MyTable
Set Field1 = tt.Field1,
Field2 = tt.Field2,
...
FROM #TempTable tt
where primaryKey = tt.PrimaryKey
Note this is kind suedo code. so replace fieldx with your field names and replace primaryKey with the primarykey field name or unique identifier field name for the table.
update requires you to determine some external logic.
for instance, if the primary key of the incoming record already exists, update the other columns, otherwise insert this record.
i might suggest you write some xslt to create update statements out of the incoming xml stream, then run that sql script.
Check out the OPENXML function. You map also want to load the XML data into a variable table so you can easily join or compose the rest of the query as you would between normal database tables.
SQL Server 2005 and up has native support for XML data types, and also supports the XQuery language for shredding XML into relational data columns.
Check out the Introduction to XQuery in SQL Server 2005 to get a feel for how this works.