adplus-dvertising
1. Which of the following code snippet insert the top level manager ‘Jeff Brown’ as hierarchy root?
a. INSERT INTO Employees
VALUES (1, 'Jeff Brown', NULL, hierarchyid::Root());
b. INSERT INTO Employees
VALUES (1, 'Jeff Brown', NULL, hierarchyid::GET());
c. INSERT INTO Employees
VALUES (1, 'Jeff Brown', NULL, hierarchyid::GetRoot());
d. INSERT INTO Employees
VALUES (1, 'Jeff Brown', NULL, hierarchy::GetRoot());
Answer: (c).INSERT INTO Employees
VALUES (1, 'Jeff Brown', NULL, hierarchyid::GetRoot());

2. Point out the correct statement.
a. HierarchyID data type maps the data as a hashmap, so when traversing the binary tree structure
b. In real scenarios, you always need to create indexes using Hierarchy ID data type
c. In HierarchyID, we create indexes in order to make the traversal efficient
d. None of the mentioned
Answer: (c).In HierarchyID, we create indexes in order to make the traversal efficient

3. Which of the following is invalid code associated with hierarchical data type?
a. CREATE TABLE H (
Node HierarchyID PRIMARY KEY CLUSTERED,
NodeLevel AS Node.GetLevel(),
ID INT UNIQUE NOT NULL,
Name VARCHAR(50) NOT NULL
)
b. CREATE TABLE H (
Node HierarchyID PRIMARY KEY NON CLUSTERED,
NodeLevel AS Node.GetLevel(),
ID INT UNIQUE NOT NULL,
Name VARCHAR(50) NOT NULL
)
c. CREATE TABLE H (
Node HierarchyID FOREIGN KEY CLUSTERED,
NodeLevel AS Node.GetLevel(),
ID INT UNIQUE NOT NULL,
Name VARCHAR(50) NOT NULL
)
d. All of the Mentioned
Answer: (c).CREATE TABLE H (
Node HierarchyID FOREIGN KEY CLUSTERED,
NodeLevel AS Node.GetLevel(),
ID INT UNIQUE NOT NULL,
Name VARCHAR(50) NOT NULL
)

4. Which of the following code is used to have a Breadth First index?
a. CREATE UNIQUE bfs_index
ON H (NodeLevel,Node)
b. CREATE UNIQUE INDEX bfs_index
ON H (NodeLevel,Node)
c. CREATE INDEX bfs_index
ON H (NodeLevel,Node)
d. CREATE UNIQUE INDEX bfs_index
ON H (NodeLevel)
Answer: (b).CREATE UNIQUE INDEX bfs_index
ON H (NodeLevel,Node)

5. Point out the wrong statement.
a. The Depth column comes in handy for performing the indent by using the Space() function
b. Stored procedures are the easiest way to extract hierarchical data
c. Inside SQL Server 2008, Microsoft introduces a new data type Index on HierarchyID to handle such type of data and reduce the complexity
d. None of the Mentioned
Answer: (b).Stored procedures are the easiest way to extract hierarchical data

6. What is purpose of GetDescendant method in the following code?
DECLARE @parent HierarchyId = HierarchyId::GetRoot()
INSERT INTO H (Node,ID,Name) VALUES (@parent.GetDescendant(NULL,NULL),2,'Johnny')
a. Takes 2 arguments
b. Takes 3 arguments
c. Takes 4 arguments
d. All of the mentioned
Answer: (a).Takes 2 arguments

7. Which of the following function returns true in the following code?
DECLARE @parent HierarchyId = (SELECT Node FROM H WHERE Name = 'Thuru')
DECLARE @parentNodeLevel INT = (SELECT NodeLevel FROM h WHERE name = 'Thuru')
SELECT Node.ToString() AS NodeText, *  FROM H WHERE Node.IsDescendantOf(@parent) = 'TRUE' 
AND Node != @parent AND 
NodeLevel = @parentNodeLevel + 1
a. IsDescendantOf
b. DescendantOf
c. IsDescendant
d. None of the mentioned
Answer: (a).IsDescendantOf

8. Which of the code deletes node H using hierarchical data type?
a. DELETE FROM H WHERE Name = ‘Steve’
b. DROP FROM H WHERE Name = ‘Steve’
c. DELETE H WHERE Name = ‘Steve’
d. All of the mentioned
Answer: (a).DELETE FROM H WHERE Name = ‘Steve’

9. Which of the following function will be used in the following code for moving nodes?
DECLARE @newParent HierarchyId = (SELECT Node FROM H WHERE name = 'Johnny')
UPDATE H SET Node = Node.__________(Node.GetAncestor(1),@newParent)
WHERE Name = 'S1'
a. GetReparentedVal
b. GetReparentedValue
c. GetValue
d. None of the mentioned
Answer: (b).GetReparentedValue

10. Which of the following code will not throw an error?
a. DECLARE @child HierarchyId = (SELECT Node FROM H WHERE Name = 'S1')
SELECT * FROM H WHERE Node = @child.GetAnces(2)
b. DECLARE @child HierarchyId = (SELECT Node FROM H WHERE Name = 'S1')
SELECT * FROM H WHERE Node = @child.GetAncestor(2)
c. DECLARE @child HierarchyId = (SELECT Node FROM H WHERE Name = 'S1')
SELECT * FROM H WHERE Node = @child.Ancestor(2)
d. None of the mentioned
Answer: (b).DECLARE @child HierarchyId = (SELECT Node FROM H WHERE Name = 'S1')
SELECT * FROM H WHERE Node = @child.GetAncestor(2)

Page 1 of 6