简体   繁体   English

如何从azure数据库中的表中删除行?

[英]How to delete a row from a table in azure database?

Am working on a windows store javascript application. 我正在开发一个Windows商店的JavaScript应用程序。 The application is integrated with Azure through the mobile service. 该应用程序通过移动服务与Azure集成。 I want to delete a particular record matching a particular id. 我想删除与特定ID匹配的特定记录。

Say if I have four columns(no,name,title,message,id) in the table(item) 假如我在表(项目)中有四列(no,name,title,message,id)

I want to delete the entire row which has id=5 and title='stackoverflow'. 我想删除id = 5和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. 假设您有对对象的引用,则需要从表中获取实际行,然后在table对象上调用del(item,callback)方法。 You can get the actual row from the list of already retrieved object, or use the where method to get it. 您可以从已检索对象的列表中获取实际行,或使用where方法获取它。

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 http://msdn.microsoft.com/en-us/library/windowsazure/jj554210.aspx

The syntax for delete is Table.del(itemOrId, options) . delete的语法是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. 如果您已经知道要删除的行的id,只需将其传递给del .. table.del(5) ,而不是首先获取该项,然后将其删除。

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. 我的初步答案假设您使用的是服务器端脚本,但听起来您正在使用JS客户端库并且它只需要一个对象。 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. 如果你真的想传递一个id,我会尝试将它作为object参数传递,然后更新服务器端删除脚本以使用Table.del(itemOrId, options) ,或者在服务器端删除脚本中添加id参数并为该对象传递null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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