Monday 29 February 2016

RDBMS Lab@Home 7

1. Write a query to retrieve the details of the product locations where cost rate is greater than 12. In addition, the locations need to be grouped into three groups, and then ranked based on the cost rate in descending order. (Use the AdventureWorks database)

Ans.

2. Display SalesOrderID, OrderQty, and UnitPrice from the SalesOrderDetail table where a similar unit price needs to be marked with an identical value. (Use the AdventureWorks database)

Ans. 

3. Write a query to return the current year price and the previous year price of a product with the Product ID, 715, over subsequent years. (Use the AdventureWorks database)

Ans. 

4. The Recipient table and the Country table in the NarrowFabrics database do not have the same data type for the CountryId attribute. The following tables show the sample structure of the two tables. 

Alter the Recipient or Country table so that they have the same data type for the CountryId attribute.
Ans . 
5. Delete the Recipient table from the NarrowFabrics database.


6. Consider the following table structures. Refer the preceding table structures for the following requirements:

 1. Create the Category table in the NarrowFabrics database. Enforce the following data integrity rules while creating the table: The CategoryId should be the primary key. The Category attribute should be unique but not the primary key. The Description attribute can allow storage of NULL values. 
2. Create the ProductBrand table in the NarrowFabrics database. Enforce the following data integrity rules while creating the table: The BrandId should be the primary key. The BrandName should be unique but not the primary key. 
3. Create the NewProduct table with the following data integrity rules in the NarrowFabrics database: The ProductId should be the primary key. The Qoh of the product should be between 0 and 200. The Photo and ProductImgPath attributes can allow storage of NULL values. The ProductName and ProductDescription attributes should not allow NULL values. The values of the CategoryId attribute should be present in the Category table. 
4. Modify the NewProduct table to enforce the following data integrity rule in the NarrowFabrics database: The values entered in the BrandId attribute should be present in the ProductBrand table.

Ans. https://drive.google.com/open?id=0B08RKBSts8D8UjFra04yd01FQjg

7. The following statement was used to remove the Category table: 
DELETE TABLE Category 
The preceding statement displays an error and aborts. Identify the error and rectify it. (Use the NarrowFabrics database)


8. Write the SQL statement to create a table named PictureDetails in the PictureLibrary database. The following table shows the structure of the PictureDetails table.


9. Create a table named LeaveDetail in the AdventureWorks database. The following table shows the structure of the LeaveDetail table.


10.  The check constraint is applied on the Number_of_days column of the LeaveDetail table. This check constraint ensures that the value inserted for the Number_of_days column is less than three. However, the leave of four days has been approved for John based on some valid reasons. The HR Manager wants to update the leave details for John but fails to assign the value, 4, in the Number_of_days column. As a database developer, what will you do to perform the preceding task? (Use the AdventureWorks database)


11. Write a query to display the structure of the Department table. (Use the AdventureWorks database)


12. Write a query to display the details of all the salespersons by using synonyms. (Use the AdventureWorks database)


13. Write a query to create a rule on the GroupName column of the Department table to accept only three values: Research and Development, Sales and Marketing, and Manufacturing. (Use the AdventureWorks database)


14. Write a statement to create a user-defined data type named quality. This data type should be varchar(100) and should not contain NULL values.


15. AdventureWorks, Inc. has set up a new store. Insert the data into the database as shown in the following table.


16. Insert the data shown in the following table into the ProductBrand table of the NarrowFabrics database.

17. The address of a vendor, Comfort Road Bicycles, has changed. You need to update the data, as shown in the following table, in the AdventureWorks database.





RDBMS Lab@home 6

1. Write a query to display the credit card number of Catherine Abel. (Use the AdventureWorks database)

Ans.

2.Write a query to display EmployeeID of those employees who belong to the department, Tool Design. (Use the AdventureWorks database)

Ans.
3.Write a query to display EmployeeID of those employees who belong to the department, Tool Design. (Use the AdventureWorks database)

Ans.
4. Write a query to display the first name and the last name of the customers along with their credit card identification number. (Use the AdventureWorks database)

Ans. 
5. Write a query to display CreditCardID, CardNumber, and ExpYear of the credit cards that do not expire in the year 2005 and 2007. (Use the AdventureWorks database)

Ans.

6. Write a query to display the sales person ID and the total number of sales orders processed by each sales person. In addition, display the commision earned by each sales person. Commision is given to each sales person at the rate of $ 10 per order. Exclude the orders where sales person ID is null. The details of the sales person who has got the maximum commision should be displayed first in the result set. (Use the AdventureWorks database)


7. Create a table named Recipient in the NarrowFabrics database to store the details of the recipients to whom the orders are dispatched. The following table provides the structure of the Recipient table.


8. NarrowFabrics, Inc. is a leading cloth manufacturing organization that manufactures and delivers clothes to the distributors. Being a database developer at NarrowFabrics, you need to create a database that will store the various database objects, such as tables, views, and indexes, used by the organization. Write the SQL statements that you can use to create a database named NarrowFabrics.


9. Create a table named Country in the NarrowFabrics database to store the country details. The following table provides the structure of the Country table.


10. LiveChain, Inc. is a leading media company that organizes events and provides photography services. After each event, the company stores the pictures taken in the event and delivers the pictures to the client on request. As a database developer, you have been assigned the task to create a database named PictureLibrary that the company can use to store the pictures.


11. John is working with Client Network Ltd as the Database Administrator. He wants to create a database to store the details of all the employees working in the organization. He needs to ensure that while saving, the data is placed in multiple file groups so that he is able to effectively manage the backup and restore operations. What should John do to perform this task?


12. You need to store the details of the offices in the central database, PictureLibrary. Write the SQL statement to create the OfficeLocation table in the PictureLibrary database. The following table shows the structure of the OfficeLocation table.


13. Write a query to make EmpDetail_FG as the default filegroup for the EmpDetail database.




Monday 22 February 2016

RDBMS Lab@Home 5

1. Write a query to display the sales person ID, territory ID, and territory name of all the sales persons in the following format. (Use the AdventureWorks database)

Ans.
Ans.  
3.Write a query to display the sales person ID and territory names for all the sales persons. If a sales person does not belong to any territory, NULL should be displayed as shown in the following format. (Use the AdventureWorks database)

Ans, 

Ans. 

4. Write a query to display the sales order ID, the product ID, and the order date for all the products in the following format. (Use the AdventureWorks database).
Ans. 

5.Write a query to display the order number, territory name, order date, and the quarter in which each order was placed in the following format. (Use the AdventureWorks database)



6. Write a query to display the sales order ID, territory name, month, and year of all the sales orders in the following format. (Use the AdventureWorks database)



7. Write a query to display the total amount due for all the sales orders rounded off to a whole number. In addition, display the sales order ID and the type of credit card through which the payment was made. (Use the AdventureWorks database)


8.  Write a query to display all the country region codes along with their corresponding territory IDs. (Use the AdventureWorks database)


9. Write a query to display the total amount due for all the orders in the AdventureWorks database in the following format:



10 Write a query to display the order date along with the sales order ID and the territory name. The order date should be displayed in the dd/mm/yyyy format. (Use the AdventureWorks database)


11. Write a query to display the sales order ID and the territory name of the orders where the month of the order is May and the year is 2004. (Use the AdventureWorks database)


12. Write a query to display the contact ID of the customers that have the 'Vista' credit card. (Use the AdventureWorks database)


13. Write a query to display the sales order IDs of the orders received from the Northeast territory. (Use the AdventureWorks database)


14.  Create a report containing the sales order ID of those orders where the total value is greater than the average of the total value of all the orders. (Use the AdventureWorks database)



15. Write a query to display the sales order IDs of the orders that have been paid through a SuperiorCard. (Use the AdventureWorks database)



16.  Write a query to display the sales order ID, the order detail ID, and the total value of those orders where the total value is greater than the maximum of the total value of order ID 43662. (Use the AdventureWorks database)


17. Write a query to display the details of those orders for which no discount was offered. (Use the AdventureWorks database)


18. Write a query to display the sales order IDs and the credit card IDs of those cards which are expiring in the year 2007. (Use the AdventureWorks database)




19. Write a query to display the average rate of the Australian Dollar, where the CurrencyRateDate is July 1, 2004. (Use the AdventureWorks database)


Friday 12 February 2016

RDBMS Lab@Home 4

1. Display EmployeeID and HireDate of the employees from the Employee table. The month and the year need to be displayed. (Use the AdventureWorks database)

Ans.

















2. Consider the following
SQL query: SELECT ProductID, LineTotal AS 'Total' FROM Sales.SalesOrderDetail Group By

Cube(LineTotal) Once executed, the preceding query generates errors. Identify the possible causes of such errors and rectify the same. (Use the AdventureWorks database)

Ans.


3. Display the details of all orders in the following format. (Use the AdventureWorks database)


Ans. 

4. Write a query to display the full name of a person in a column named Person Name. (Use the AdventureWorks database)

Ans
.

5. Display the customer ID, name, and sales person ID for all the stores. According to the requirement, only first 15 letters of the customer name should be displayed. (Use the AdventureWorks database)

Ans.

6.Display a report containing the sales order ID and the average value of the total amount greater than $ 5,000 in the following format. (Use the AdventureWorks database)



Ans.


7.Display the Order ID of the top five orders based on the total amount due in the year 2001. (Use the AdventureWorks database)


Ans.


8. Display the total value of all the orders put together. (Use the AdventureWorks database)

Ans.


9.What will be the output of the following code written to display the total order value for each order? (Use the AdventureWorks database) SELECT SalesOrderID,ProductID,sum(LineTotal) FROM Sales.SalesOrderDetail GROUP BY SalesOrderID




10.  Display the maximum, minimum, and the average rate of sales orders. (Use the AdventureWorks database)


Ans.


11.  Display the maximum, minimum, and the average rate of sales orders. (Use the AdventureWorks database)




12.Consider the following SQL query containing the ROLLUP operator: 
SELECT ProductID, LineTotal AS 'Total' FROM Sales.SalesOrderDetail GROUP BY ROLLUP (ProductID)
The preceding query generates errors during execution. Identify the possible causes of such errors and rectify? (Use the AdventureWorks database)





13.Display the sales order ID and the maximum and minimum values of the order based on the sales order ID. In addition, ensure that the order amount is greater than $ 5,000. (Use the AdventureWorks database)




14. Display a report containing the product ID and the total cost of products for the product ID whose total cost is more than $ 10,000. (Use the AdventureWorks database)




15. Display the sum of sales amount earned by each sales person and the sum of sales amount earned by the all the salespersons. (Use the AdventureWorks database)




16. Display the total unit price and the total amount collected after selling the products, 774 and 777. In addition, calculate the total amount collected from these two products. (Use the AdventureWorks database)



17. Write a query to retrieve the list price of the products where the product price is between $ 360.00 and $ 499.00 and display the price in the following format:
 The list price of "Product Name" is "Price". (Use the AdventureWorks database)






Thursday 11 February 2016

RDBMS Lab@Home 3

1. Display the details of those stores that have Bike in their name. (Use the AdventureWorks database)

Ans.

2.Display all territories whose names begin with 'N'. (Use the AdventureWorks database)


Ans .

3.Display the top three sales persons based on the bonus. (Use the AdventureWorks database)

Ans. 

4.Display the SalesPerson ID, the Territory ID, and the Sales Quota for those sales persons who have been assigned a sales quota. The data should be displayed in the following format. (Use the AdventureWorks database)

Ans 

5. Display a report that contains the employee ID, login ID, and the title of employees. The report should display the records for 10 employees after excluding the records of the first five employees. (Use the AdventureWorks database).



6. Display the different types of credit cards used for purchasing products. (Use the AdventureWorks database)

Ans. 
7. New Heights is a training institute that provides courses on various nontechnical subjects, such as personality improvement and foreign languages. Xuan, the Database Designer, has made the following relations to represent the data about students, batches, and modules covered in the batches: STUD-ID: Student's id (unique) 
 NAME: Name of student 
BATCH-NO: Batch number (one student can belong to only one batch) 
 SLOT: Time and day when the batch of students attends the class 
 MODULE: Module or subject (one batch will do several modules)
 MARKS: Marks obtained in a module test Xuan now needs to simplify the above relations by normalizing them.


8. Consider the following 

Student table. The preceding table is in the first normal form. How can this table be converted into the second normal form?


9. Consider the following 

Product table. The preceding table is not normalized. How can this table be converted into the first normal form?


10. Consider the following Purchase_Details table. 

Cust_ID and StoreID make the composite primary key in the table. Identify the partial dependency in the table, if any. How can you remove the partial dependency to attain the next normal form?

Sunday 7 February 2016

RDBMS Lab@Home 2

Q.1. Display the ID, type, number, and expiry year of all the credit cards in the following format. (Use the AdventureWorks database)





Ans  https://drive.google.com/open?id=0B08RKBSts8D8UGFrMVkxQmZhMTA


Q.2.  Display the details of all the customers. (Use the AdventureWorks database)


Ans. https://drive.google.com/open?id=0B08RKBSts8D8ajlSU1B3clVicUU


Q.3.  Display all the details of the sales orders that have a cost exceeding $ 2,000. (Use the AdventureWorks database)


Ans.  https://drive.google.com/open?id=0B08RKBSts8D8SFRnUjB5eDhQMnc


Q.4.  Display the customer ID and the account number of all the customers who live in the TerritoryID 4. (Use the AdventureWorks database)


Ans.  https://drive.google.com/open?id=0B08RKBSts8D8SDg4OE8yVExRbTg


Q.5.  Display the list of all the orders placed on June 06, 2004. (Use the AdventureWorks database)


Ans   https://drive.google.com/open?id=0B08RKBSts8D8QWxGSnBZbko5ZTQ


Q. 6  Display the sales order details of the product named 'Cable Lock' for which the ProductId is 843. (Use the AdventureWorks database)

Ans   https://drive.google.com/open?id=0B08RKBSts8D8a0VkclEwRUpzc0k


Q.7.  Display the name, country region code, and sales year to date for the territory with Territory ID as 1. (Use the AdventureWorks database)


Ans  https://drive.google.com/open?id=0B08RKBSts8D8YWpnMWJLOFh1eUU


Q.8. Display a list of all the sales orders in the price range of $ 2,000 to $ 2,100. (Use the AdventureWorks database)


Ans   https://drive.google.com/open?id=0B08RKBSts8D8RngtTzlHbTd4VU0


Q.9.   Display the sales territory details of Canada, France, and Germany. (Use the AdventureWorks database)


Ans   https://drive.google.com/open?id=0B08RKBSts8D8WTVROWQxZ2M4Ymc


Q.10.   Display the details of the orders that have a tax amount of more than $ 10,000. (Use the AdventureWorks database)


Ans    https://drive.google.com/open?id=0B08RKBSts8D8akdpSDVTaDhIOGM


Q.11.  Generate a report that contains the IDs of sales persons living in the territory with TerritoryID as 2 or 4. The report is required in the following format. (Use the AdventureWorks database)


Q.12.  Display the details of the Vista credit cards that are expiring in the year 2006. (Use the AdventureWorks database)




Q.13.   Display the orders placed on July 01, 2001 that have a total cost of more than $ 10,000 in the following format. (Use the AdventureWorks database)



Q.14.  Display the details of all the orders that were shipped after July 12, 2004. (Use the AdventureWorks database)




Q.15.  Display a report of all the orders in the following format. (Use the AdventureWorks database)



Q.16.  Display the order ID and the tax amount for the sales orders that are less than $ 2,000. The data should be displayed in ascending order. (Use the AdventureWorks database)



Q.17.  Display the order ID and the total amount due of all the sales orders in the following format. Ensure that the order with the highest price is at the top of the list. (Use the AdventureWorks database)



Q. 18.  Display the order number and the total value of the order in ascending order of the total value. (Use the AdventureWorks database)




Q.19..  Display the details of all the currencies that have the word 'Dollar' in their name. (Use the AdventureWorks database)