- Exercise 2
The Store table is often queried. The queries are based in the CustomerID attribute and take along to execute
create unique nonclustered index Idx_CustomerID on Sales.Store(CustomerID)
- Exercise 3
The SalesOrderDetail table is often queried
create nonclustered index Idx_SalesOrderId_SalesOrderDetailId on Sales.SalesOrderDetail(SalesOrderId, SalesOrderDetailId)
- Exercise 4
A view has been defined as shown in the following statement
create view vxSalesOrderDetail
as
select oh.SalesOrderID, TerritoryID, TotalDue, OrderQty, ProductID
from Sales.SalesOrderHeader oh join Sales.SalesOrderDetail od on oh.SalesOrderID=od.SalesOrderID
The following update statement gives an error when you update the OrderQty and TerritoryID attribute:
update vwSalesOrderDetail
set OrderQty=2, TerritoryID=4
from vwSalesOrderDetail
where SalesOrderID = 43659
Identify the problem and provide the solution
update vwSalesOrderDetail
set OrderQty=2
from vwSalesOrderDetail
where SalesOrderID = 43659
update vwSalesOrderDetail
set TerritoryID=4
from vwSalesOrderDetail
where SalesOrderID = 43659
- Exercise 5
The Store table contains the details of all the stores.Write a query to retrieved the result set quickly
create fulltext catalog cat3 as default
create fulltext index on Sales.Store(Name)
key index PK_Store_CustomerID
select * from Sales.Store
where FreeText (name,'Bike')
select * from Sales.Store
where Contains (name,'"Bike Store"')
- Exercise 6
Display the detail of all the credit crds are of type "SuperiorCard".Optimize the execution time.
create fulltext catalog cat4 as default
create fulltext index on Sales.CreditCard(CardType)
key index AK_CreditCard_CardNumber
select *from Sales.CreditCard
where Contains (CardType,'"SuperiorCard"')
- Exercise 7
Display the details of all the currencies that contain the words 'New' and 'Dollar' in their name.Optimize the Result Set.
Create fulltext index on Sales.Currency(Name)
key index AK_Currency_Name
select *from Sales.Currency
where Contains (Name,'"New"') and (Name,'"Dollar"')
- Exercise 8
The manager of the producion department wants to analyze the products that contain the exact word "road" in their description.Query to optimize the result set.
select * from Production.ProductDescription
where Contains (Description ,'road')
- Exercise 9
The report of the all product that contain the exact word "top" near the word "line" in their description.Query to optimize the result set.
select Description, ProductDescriptionID from Production.ProductDescription
where Contains (Descripton,'"top" near "line"')
- Exercise 10
Display the details of all the stores having the word 'bike' in their name.Also report contains the details of those stores that have the SalesPersonID as 277.Optimize the query
select * from Sales.Store where
SalesPersonID =277 and Contains (Name,'Bike')
- Exercise 11
The DepartmentHistory table of employee is often queried. The queries are based on the EmployeeID attribute and take a long time to execute.Optimize the execution
create nonclustered index Idx_EmployeeId
on HumanResousce.EmployeeDepartmentHistory(EmployeeID)
- Exercise 12
The Store table is queried based on Demographical attribute and take a long time to execute.Optimize the execution
create xml index Sdx_Sales_Demographics_PATH
on Sales.Store (Demographics)
using xml index PXML_Store_Demographics
FOR PATH
- Exercise 13
Create a view to retrive the employeeIDs along with the corresponding Group Name.
create view Disp_Details
as
select E.EmployeeId, D.GroupName
from HumanResources.Department D
inner join
HumanResources.EmployeeDepartmentHistory E
on D.DepartmentId = E.DepartmentId
- Exercise 14
Create a view to retrive SalesOrderId and Price of the Product along with corresponding Product Name
create view vxSales
as
select P.Name, S.SalesOrderID, S.UnitPrice
from Production.Product P inner join
Sales.SalesOrderDetail S
on P.ProductID=S.ProductID
- Exercise 15
Create a view to display salesOrderId, CustomerId, OrderQty, UnitPrice, SubTotal and TotalDue of the orders placed.
create view vxSale as
select H.CustomerID, H.SubTotal, H.TotalDue,
D.SalesOrderID, D.OrderQty, D.UnitPrice
from Sales.SalesOrderHeader as H
join Sales.SalesOrderDetail as D
on H.SalesOrderID = D.SalesOrderID
No comments:
Post a Comment