Monday 29 February 2016

NIIT SQL LAB@HOME 2


1. Display the details of all customers

ANSWER: Select *
                   From Sales.Customer


2.Display the ID,type,number,and expiry year of the credit cards

ANSWER:  Select 'CreditCardID=CreditCardId, 'CreditCardType' =                 Cardtype,'Credit Card Number' = CardNumber
                    'Expiry Year'= ExpYear
                    From Sales.CreditCard


3.Display the Customer ID and the account number of all the customer who live in the TerritoryID 4

ANSWER: Select Customer Id,account number
                   From Sales.Customer
                   Where TerritoryID = 4


4.Display all the details of the sales order that have a cost exceeding $2000.

ANSWER: Select *
                   From Sales.SalesOrderDetail
                   Where LineTotal > 2000.00


5.Display the sales order details of the product named 'Cable Lock' for which the product Id is 843.

ANSWER: Select *
                   From Sales.SalesOrderDetail
                   Where Product Id =843


6.Display the list of all the orders placed on June 06,2004.

ANSWER: Select *
                   From Sales.SalesOrderHeader
                   Where Order Date = '06-06-2004'

                   
7.Display the Name,Country region code,and sales year to date for territory with Territory ID as 1.

ANSWER: Select Country Region Code,Sales YTD
                   From Sales.SalesTerritory 
                   Where Territory ID = 1


8.Display lists of all the sales orders in the price range of $ 2000 to $ 2100.

ANSWER: Select *
                   From Sales.SalesOrderDetail
                   Where Line Total between 2000 and 2100


9.Display the Sales territory details of Canada,France and Germany.

ANSWER: Select *
                   From Sales.SalesTerritory 
                   Where name IN ('Canada','France','Germany')


10.Display the details of the orders that have tax amount of more than $10000.

ANSWER:  Select *
                   From Sales.SalesOrderHeader
                   Where Tax amt >=10000

11.Generate a report that contains the IDs of sales persons living in the territory ID as 2 or 4.

ANSWER: Select Sales Person ID ,Territory ID
                   From Sales.SalesTerritoryHistory
                   Where Territory ID =2 OR Territory ID = 4

12.Display the detail of the vista credit cards that are expiring in the year 2006.

ANSWER: Select *
                   From Sales.CreditCard
                   Where Card type = 'Vista' AND ExpYear = '2006' 

13.Display the Orders placed on July 01,2001 that have a total cost of more than $ 10000.

ANSWER: Select 'Order Number' = Sales Order ID ,'Order Date' =                    Order Date,Status,'Total Cost' = Total Due
                   From Sales.SalesOrderHeader
                   Where Order Date = '07-01-2001' 
                   AND Total Due >10000

14.Display the details of the all orders that were shipped after
  July 12,2004.

ANSWER: Select *
                   From Sales.SalesOrderHeader
                   Where Ship Date >'2004-07-12'

15.Display a report of all the Orders.

ANSWER: Select 'Order ID' = Sales Order ID, 'Order Quantity' =                      Order Qty,'Unit Price' = Unit Price, Total Cost = Order                    Qty * Unit Price 
                   From Sales.SalesOrderDetail

16.Display the details of the orders that have been placed by customers online.

ANSWER: Select *
                   From Sales.SalesOrderHeader
                   Where OnlineOrderFlag = 1

17.Display the Order ID and the Total amount due of all the sales orders.Ensure that the order with the highest price is at the top of the list.

ANSWER: Select 'Order ID' = Sales Order ID, 'Total Due' = Total                      Due
                   From Sales.SalesOrderHeader
                   Order by Total Due desc

18.Display the Order ID and Tax amount for the sales orders that are less than $2000. The data should be displayed in ascending order.

ANSWER: Select Sales Order ID, Tax Amt
                   From Sales.SalesOrderHeader
                   Where Total Due <2000
                   Order by Total Due asc

19.Display the Order number and the total value of the order in ascending order of the total value.

ANSWER: Select Sales Order ID, Total Due
                   From Sales.SalesOrderHeader
                   Order by Total Due asc

20.Display the details of all the currencies that have the word 'Dollar' in their name.

ANSWER: Select *
                   From Sales.Currency
                   Where Name like '%Dollar%'
                   
                                                NIIT RDBMS LAB@HOME 1


1.Shopping Spree is a leading departmental store in Shanghai.The store has a number of regular customers who purchase bulk items.The store also conducts regular feedback sessions to analyze customer satisfaction levels.Chen, the customer analyst of shopping spree, has to make ER diagram to represent the preceding situation, and then to map the ER diagram to the corresponding table.Help Chen to do the same.

ANSWER:





2.An organization has two types of employees,salaried and wage earning.Both the types of employees has some common properties,such as employee code,employee name, and employee address.However,the salaried employees have other additional properties:basic,allowance,and House Rent Allowance(HRA). The wage earning employees have distinct properties that are daily wage and overtime.

ANSWER:




3.


ANSWER:
Primary Key: DoctorID
Candidate Key: DoctorID,ShiftID
Alternate Key: Qualification

DoctorID and ShiftID are individually unique in every row.Therefore,the columns, DoctorID and ShiftID,are Candidate keys for primary key.However,the ShiftID column may contain duplicate values as two doctors may be on the same Shift.Therefore,DoctorID should be chosen as the primary key and ShiftID as the Alternate key.



4.You have been hired by a regional hospital to create a database that will be used to store the information of the patients.Implementing the database will make the date easily accessible.Identify the entities, their attributes,and the type of relationship between the entities.

ANSWER:
Entities: Patient,Doctor
Attributes of Patient: Patient_Name,Date_admitted,Patient_ID
Attributes of Doctor:
Doc_ID,Specialization,Doc_Name
Relationship :
Many to Many



5.Tom is working in an organization as a database administrator.Based on the hierarchy, the organization has multiple departments and each department has multiple employees.Identify entities,their attributes, and type of relationship between the entities.

ANSWER:
Entities: Employee,Department
Attributes of Employee:
EmpID,EmpName,DepID
Attributes of Department:
DepID,DepName,DepHead



6. Lee Wong is the newly appointed database administrator at Standard bank.The management of this bank wants to computerize the process of banking.According to the bank's policy,one customer can have many accounts but one account cannot be shared by many customers.Identify entities,their attributes,and type of relationship between the entities.

ANSWER:

Entities: Customer,Account
Attributes of Customer:
Customer Name,SSN Number ,Customer Address
Attributes of Account:
Account Number,Balance
Relationship: One to Many



7.An author can write multiple books and a book can be written by more than one author.Identify the relationship between the entity.Represent it with an ER Diagram.

ANSWER:


Relationship: Many to Many