简体   繁体   中英

How to delete a row from a table in azure database?

Am working on a windows store javascript application. The application is integrated with Azure through the mobile service. I want to delete a particular record matching a particular id.

Say if I have four columns(no,name,title,message,id) in the table(item)

I want to delete the entire row which has id=5 and title='stackoverflow'. What code will perform that operation?

Given you got a reference to the table object, you need to get actual row from the table and then just call del(item, callback) method on the table object. You can get the actual row from the list of already retrieved object, or use the where method to get it.

Something similar to:

var myTable = client.getTable('MyItem');
// here is a code to get the actual item
myTable.del(item);

or more simplistic:

myTable.where({ id: 5, titile: "stackoverflow" })
    .read()
    .done(function (results) {
        var result = results[0];
        if (result != null && typeof (result) != "undefined") {
            todoTable.del(result);
        }
    });

As per the mobile services server script reference:

http://msdn.microsoft.com/en-us/library/windowsazure/jj554210.aspx

The syntax for delete is Table.del(itemOrId, options) . If you already know the id of the row you want to delete, just pass that to del.. table.del(5) , rather than first getting the item and then deleting it.

My initial answer assumed you were using server side scripting, but it sounds like you are using the JS client library and that it only takes an object. If you really want to just pass an id I would try either passing it as the object parameter and then update your server side delete script to use Table.del(itemOrId, options) , or, add the id parameter in your server side delete script and pass null for the object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM