CREATE DATABASE Dirs
GO

USE Dirs
GO

CREATE TABLE Dirs (
  ID INT PRIMARY KEY IDENTITY(1,1),
  Name nvarchar(30) NOT NULL,
  L INT NOT NULL,
  R INT NOT NULL,
  Parent INT NOT NULL
)


DECLARE @RL INTEGER
SET @RL = (SELECT L FROM Dirs WHERE Name = 'root')
PRINT @RL

DECLARE @RR INTEGER
SET @RR = (SELECT R FROM Dirs WHERE Name = 'root')
PRINT @RR

INSERT INTO Dirs VALUES ('etc',@RL+1,@RL+2)

UPDATE Dirs SET L = L + 2 WHERE L > @RL
UPDATE Dirs SET R = R + 2 WHERE R > @RL

SELECT * FROM Dirs

SELECT * FROM Dirs WHERE Name = 'bin'

SELECT ID,Name FROM Dirs WHERE L > 4 AND R < 7




SELECT * FROM Dirs

