我有这两个表:
表:原因
id | name
---|------------
1 | gold_sell
2 | gold_buy
4 | Silver_sell
表:REASON_TO_TRANSACTION
reason_id | transaction_type
----------|-------------------
1 | sell
2 | buy
4 | pko
其中表id
中的reason
与reason_id
中的reason_to_transaction
链接。
我想从这两个表中删除id
= 1的所有行。
有人可以帮我吗?
我正在使用SQL Server(phpmyadmin)。
变量name
用于获取当前的activeItem
并将其删除。
我编写了以下SQL命令:
DELETE rt
FROM reason_to_transaction rt
INNER JOIN reasons r
ON id=reason_id
WHERE reasons.id=reason_to_transaction.reason_id
AND name = 'gold_sell'
我也有这个角度代码:
$scope.deleteItem = function(){
console.log($scope.activeItem);
var objectToSave = {
name: $scope.activeItem.name,
id: $scope.activeItem.id
};
if($scope.activeItem.id){
defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',
{ replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE }
).then(projects => {
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
});
} else {
defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',
{ replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE }
).then(projects => {
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
});
}
};
也有html提交表单:
<div class="editMode1" style="display: none;">
<div class="form">
<form ng-submit="saveItem(reasonsForm.$valid)" name="reasonsForm">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="currency_code">Име на основание</label>
<input type="text" class="form-control" required ng-model="activeItem.name" placeholder="Име на основание за редактиране" />
</div>
</div>
</div>
<button class="btn btn-primary" ng-disabled="reasonsForm.$invalid" type="submit">Save</button>
<button class="btn btn-primary" type="submit" ng-click="deleteItem()">Delete</button> <!--ng-click="createUser()"-->
<button class="btn btn-primary" id="cnlbtn" type="button">Cancel</button>
</form>
</div>
</div>