从数据库中删除树节点记录 [英] Delete Tree Node Records from Database
本文介绍了从数据库中删除树节点记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Treeview控件,并想从关系表中删除记录.
我有这样的表结构
Hi,
I am using treeview control and wanted to delete the records from the relation table.
I am having table structure like this
Node id Parent id
1 0
2 1
3 1
4 2
5 3
6 4
7 5
如果我选择第一个节点(即0,即根节点),那么我想从数据库中删除所有记录
谢谢
Sjs4u
If I select 1st Node(is 0 i.e. Root node) then I want to delete all the records from the database
Thanks
Sjs4u
推荐答案
由于递归和性能问题,不建议在数据库中实现树结构,但是这里有一些很好的链接:
邻接列表模型
在MySQL中管理分层数据
MySQL中的树和其他层次结构
Implementing tree structures in a database is not recommended because of recursion and performance issues, but here are a few good links :
Adjacency List Model
Managing Hierarchical Data in MySQL
Trees and Other Hierarchies in MySQL
设置QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_TreeNode_select]
@TreeNodeID INT
AS
开始
设置NOCOUNT ON;
开始
SELECT TreeNodeID
,ISNULL(ParentNodeID,0)ParentNodeID
,标题
来自[dbo].[TreeNode]
在哪里(@TreeNodeID = 0或TreeNodeID = @TreeNodeID)
ORDER BY ParentNodeID,TreeNodeID
END
END
/***存储过程3 ***/
您可以找到所有子节点,然后根据TreeNode Id删除查询Fire From.
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_TreeNode_select]
@TreeNodeID INT
AS
BEGIN
SET NOCOUNT ON;
BEGIN
SELECT TreeNodeID
, ISNULL(ParentNodeID, 0) ParentNodeID
, Title
FROM [dbo].[TreeNode]
WHERE (@TreeNodeID = 0 OR TreeNodeID = @TreeNodeID)
ORDER BY ParentNodeID, TreeNodeID
END
END
/*** STORED PROCEDURE 3 ***/
u can find all child corresponding node then delete query Fire From According to TreeNode Id
这篇关于从数据库中删除树节点记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文