In actual work, we often encounter situations that require multi-level directories. For example, when designing a forum, its layout is hierarchical and there is no limit to this classification for flexible expansion. That is to say, the designers, the number of directories set by the user is not limited.
In view of this situation, the design scheme I proposed is as follows: first design the following Table (taking SQL Server as an example)
Create table [layout TABLE] (
[Id] [int] IDENTITY (1, 1) not null,
[Layout name] [varchar] (30) COLLATE Chinese_PRC_CI_AS not null,
[Layout level] [varchar] (30) COLLATE Chinese_PRC_CI_AS not null,
[Parent layout id] [int] NOT NULL
) ON [PRIMARY]
The top-level layout id is its own layout id.
Enter the following data:
Id
Layout name layout level
Superior layout id
1
English learning
1
1
2
Level 4 and Level 6 learning
2
1
3
GRE
2
1
4
GRE composition
3
3
5
GRE vocabulary
3
3
6
GRE reading
3
3
7
GRE filling
3
3
8
GRE composition peer evaluation
4
4
9
GRE composition outline
4
4
10
TOEFL
2
1
11
TOEFL composition
3
10
12
TOEFL listening
3
10
13
TOEFL reading
3
10
14
TOEFL syntax
3
10
15
Sports
1
15
16
Football
2
15
17
Chinese soccer
3
16
18
World Soccer
3
16
19
Basketball
2
15
20
CBA
3
19
21
NBA
3
19
Create the following stored procedure to read all parent layout IDs of a layout.
-- Create a layout to traverse the stored procedure of the parent directory
Create procedure TraverseByName
@ Name varchar (30) -- layout name
AS
Declare @ I int -- level loop variable
Declare @ str varchar (30) -- Temporary string variable
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.